install.packages("ggplot2") require(ggplot2) # Data Note: ggplot2 requires data.frames
Friday, March 13, 2015
install.packages("ggplot2") require(ggplot2) # Data Note: ggplot2 requires data.frames
ggplot() + layer( data = diamonds, mapping = aes(x= carat, y = price, color = cut, alpha = 0.5) , geom = "point" , stat = "identity" , position = "identity" ) + layer( data = diamonds, mapping = aes(x = carat, y = price) , geom = "smooth" , stat = "smooth" , method = lm, position = "identity" , ) + scale_y_log10() + scale_x_log10() + coord_cartesian()
Translation: using the diamonds data set, map 'carat' to horizontal (x) position and 'price' to vertical (y) position. Display the raw data with points that are colored according to the variable 'cut'. Finally, add a smoothing line with all of the same data mapping onto a log-transformed axis scale.
…a mess
Allow us to simplify the full ggplot() specification to:
ggplot(diamonds, aes(carat, price)) + geom_point() + stat_smooth(method = lm) + scale_y_log10() + scale_x_log10()
p + geom_errorbar(aes(x = , ymax = , ymin = )) #required aesthetics
ggsave("plot.png" , plot = last_plot() , width = , height = , units = )
What should I do to make my life easier when using ggplot2?
This repo on GitHub - all materials, including slides
Also has links to more teaching resources on all these things