tech talk ggplot2

Download Tech talk   ggplot2

Post on 26-Jan-2015

108 views

Category:

Entertainment & Humor

3 download

Embed Size (px)

DESCRIPTION

A quick introduction to the ggplot2 R package by Hadley Wickham which implements the Grammar of Graphics paradigm in the R language.

TRANSCRIPT

  • 1. Slides adapted/stolen from Garret Grolemund/RStudiosData Visualization Courseggplot2Jeff Allen Quantitative Biomedical Research Center 3.18.13

2. Getting Startedinstall.packages(c("ggplot2", "hexbin","ggmap", "maps", "RColorBrewer","scales","ReadImages"))library(ggplot2)library(hexbin)library(ggmap)library(maps)library(RColorBrewer)library(scales)library(ReadImages) 3. Grammar of Graphics Framework for describing visualized data Mapping data onto a coordinate system Created by Leland Wilkinson 4. Your First ggplot2 Plot> library(ggplot2)> head(mpg)manufacturer model displ year cyltrans drv cty hwy fl class1 audi a41.8 1999 4 auto(l5) f 18 29 p compact2 audi a41.8 1999 4 manual(m5) f 21 29 p compact3 audi a42.0 2008 4 manual(m6) f 20 31 p compact4 audi a42.0 2008 4 auto(av) f 21 30 p compact5 audi a42.8 1999 6 auto(l5) f 16 26 p compact6 audi a42.8 1999 6 manual(m5) f 18 26 p compact 5. Your First ggplot2 Plotggplot(data=mpg, aes(x=cty, y=hwy)) + geom_point() 6. Your First ggplot2 Plot Thedata.frameto plotggplot(data=mpg, aes(x=cty, y=hwy)) + geom_point() 7. Your First ggplot2 Plot Thedata.frame Aestheticto plotMappingsggplot(data=mpg, aes(x=cty, y=hwy)) + geom_point() 8. Your First ggplot2 Plot Thedata.frame Aestheticto plotMappingsggplot(data=mpg, aes(x=cty, y=hwy)) + geom_point()What geomto use in plotting 9. Your First ggplot2 Plotlibrary(ggplot2)ggplot(data=mpg,aes(x=cty, y=hwy))+ geom_point() 10. ImprovementsProblem: verbosityggplot(data=mpg,aes(x=cty, y=hwy))+ geom_point()ggplot(mpg, aes(cty, hwy))+ geom_point() 11. ImprovementsProblem: OverplottingSolution: Different geomsggplot(mpg, aes(cty, hwy))+ geom_jitter() 12. ImprovementsProblem: OverplottingSolution: Different geomsggplot(mpg, aes(cty, hwy))+ geom_bin2d() 13. Colors & Groupsggplot(mpg, aes(cty, hwy,color=drv))+ geom_jitter() 14. Colors & Groupsggplot(mpg,aes(drv, hwy))+ geom_boxplot() 15. Adding Layersggplot(mpg,aes(drv, hwy))+ geom_jitter()+ geom_boxplot() 16. Adding Layersggplot(mpg, aes(cty, hwy))+ geom_jitter()+ geom_smooth() 17. Adding Layersggplot(data, aes(TIME, Y, color=GROUP)) +geom_line() + geom_smooth() 18. Facetingggplot(mpg, aes(cty, hwy)) + geom_jitter()+ facet_grid(drv ~ class) 19. Refining Plotsggplot(mpg, aes(cty, hwy))+ geom_jitter()+ xlab("City MPG")+ ylab("Hwy MPG")+ ggtitle("City vsHighway MPG") 20. Etc. 21. Etc. 22. Etc. 23. Etc. 24. Etc. 25. Etc. 26. Etc. 27. Etc. 28. Resources http://docs.ggplot2.org/ Google Group ggplot2 Book