Created
December 12, 2012 20:35
-
-
Save mkulakowski2/4271373 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ggplot is an implementation of the grammar of graphics in R | |
library("ggplot2") | |
#Load the data into F1_POS dataframe | |
F1_POS <- read.csv("E:/R/f1/F1_POS.csv") | |
#The drivers are ordered by points, and the Salary variable converted to a factor for sorting. | |
F1_POS$Driver <- with(F1_POS, reorder(Driver, Salary)) | |
library("reshape2") | |
#Convert the data for easy casting and rescale the stats. | |
F1_POS.m <- melt(F1_POS) | |
library("plyr") | |
library("scales") | |
F1_POS.m <- ddply(F1_POS.m, .(variable), transform, rescale = rescale(value)) | |
#Plot the data. | |
(p <- ggplot(F1_POS.m, aes(variable, Driver)) + geom_tile(aes(fill = rescale), colour = "white") + scale_fill_gradient(low = "red",high = "yellow")) | |
base_size <- 9 | |
p + theme_grey(base_size = base_size) + labs(x = "", y = "") + scale_x_discrete(expand = c(0, 0)) + scale_y_discrete(expand = c(0, 0)) + opts(legend.position = "none", axis.ticks = theme_blank(), axis.text.x = theme_text(size = base_size * 0.8, angle = 330, hjust = 0, colour = "grey50")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment