(very) basic graphing with r
TRANSCRIPT
![Page 1: (Very) Basic graphing with R](https://reader034.vdocument.in/reader034/viewer/2022042714/554e8332b4c905f66a8b5625/html5/thumbnails/1.jpg)
Graphingwith
2012-11-19 @HSPHKazuki Yoshida, M.D. MPH-CLE student
FREEDOMTO KNOW
![Page 2: (Very) Basic graphing with R](https://reader034.vdocument.in/reader034/viewer/2022042714/554e8332b4c905f66a8b5625/html5/thumbnails/2.jpg)
Group Website is at:
http://rpubs.com/kaz_yos/useR_at_HSPH
![Page 3: (Very) Basic graphing with R](https://reader034.vdocument.in/reader034/viewer/2022042714/554e8332b4c905f66a8b5625/html5/thumbnails/3.jpg)
n Introduction
n Reading Data into R (1)
n Reading Data into R (2)
n Descriptive, continuous
n Descriptive, categorical
Previously in this group
Group Website: http://rpubs.com/kaz_yos/useR_at_HSPH
![Page 4: (Very) Basic graphing with R](https://reader034.vdocument.in/reader034/viewer/2022042714/554e8332b4c905f66a8b5625/html5/thumbnails/4.jpg)
Menu
n Basic graphing with R
![Page 5: (Very) Basic graphing with R](https://reader034.vdocument.in/reader034/viewer/2022042714/554e8332b4c905f66a8b5625/html5/thumbnails/5.jpg)
Ingredients
n One-variable plot
n Histogram
n Density plot
n Two-variable plot
n Scatter plot
n Box plot
n Grouped plot
n base, lattice, and ggplot2
n hist(), histogram()
n densityplot()
n plot(Y~X)
n boxplot(), bwplot()
n Conditioning in lattice
Statistics Programming
![Page 6: (Very) Basic graphing with R](https://reader034.vdocument.in/reader034/viewer/2022042714/554e8332b4c905f66a8b5625/html5/thumbnails/6.jpg)
3 different systems
![Page 7: (Very) Basic graphing with R](https://reader034.vdocument.in/reader034/viewer/2022042714/554e8332b4c905f66a8b5625/html5/thumbnails/7.jpg)
base (traditional)
http://commons.wikimedia.org/wiki/File:Plottype.png
![Page 8: (Very) Basic graphing with R](https://reader034.vdocument.in/reader034/viewer/2022042714/554e8332b4c905f66a8b5625/html5/thumbnails/8.jpg)
lattice package
http://zoonek.free.fr/blosxom/R/2006-08-10_R_Graphics.html
![Page 9: (Very) Basic graphing with R](https://reader034.vdocument.in/reader034/viewer/2022042714/554e8332b4c905f66a8b5625/html5/thumbnails/9.jpg)
ggplot2
http://blog.revolutionanalytics.com/2009/09/ggplot2-and-the-grammar-of-graphics.html
![Page 10: (Very) Basic graphing with R](https://reader034.vdocument.in/reader034/viewer/2022042714/554e8332b4c905f66a8b5625/html5/thumbnails/10.jpg)
Open R Studio
![Page 11: (Very) Basic graphing with R](https://reader034.vdocument.in/reader034/viewer/2022042714/554e8332b4c905f66a8b5625/html5/thumbnails/11.jpg)
lattice ggplot2Install and Load
![Page 12: (Very) Basic graphing with R](https://reader034.vdocument.in/reader034/viewer/2022042714/554e8332b4c905f66a8b5625/html5/thumbnails/12.jpg)
http://www.cengage.com/cgi-wadsworth/course_products_wp.pl?fid=M20bI&product_isbn_issn=9780538733496
Download comma-separated and Excel
BONEDEN.DAT.txtBETACAR.DAT.txt
Put them in folder
![Page 13: (Very) Basic graphing with R](https://reader034.vdocument.in/reader034/viewer/2022042714/554e8332b4c905f66a8b5625/html5/thumbnails/13.jpg)
Read in BONEDEN.DAT.txt
Name it bone
Bone density in twins with discordant smoking exposure
![Page 14: (Very) Basic graphing with R](https://reader034.vdocument.in/reader034/viewer/2022042714/554e8332b4c905f66a8b5625/html5/thumbnails/14.jpg)
Read in BETACAR.DAT.txt
Name it vitA
Plasma level of carotene by different formula of beta-carotene
![Page 15: (Very) Basic graphing with R](https://reader034.vdocument.in/reader034/viewer/2022042714/554e8332b4c905f66a8b5625/html5/thumbnails/15.jpg)
Y-axis ~ X-axis
formula
![Page 16: (Very) Basic graphing with R](https://reader034.vdocument.in/reader034/viewer/2022042714/554e8332b4c905f66a8b5625/html5/thumbnails/16.jpg)
Histogram
![Page 17: (Very) Basic graphing with R](https://reader034.vdocument.in/reader034/viewer/2022042714/554e8332b4c905f66a8b5625/html5/thumbnails/17.jpg)
## basehist(bone$age)
## latticehistogram(bone$age)
## ggplot2qplot(x = age, data = bone, geom = "Histogram")
![Page 18: (Very) Basic graphing with R](https://reader034.vdocument.in/reader034/viewer/2022042714/554e8332b4c905f66a8b5625/html5/thumbnails/18.jpg)
Density plot
![Page 19: (Very) Basic graphing with R](https://reader034.vdocument.in/reader034/viewer/2022042714/554e8332b4c905f66a8b5625/html5/thumbnails/19.jpg)
## baseplot(density(bone$age))
## latticedensityplot(bone$age)
## ggplot2qplot(x = age, data = bone, geom = "density")
![Page 20: (Very) Basic graphing with R](https://reader034.vdocument.in/reader034/viewer/2022042714/554e8332b4c905f66a8b5625/html5/thumbnails/20.jpg)
Scatter plot
![Page 21: (Very) Basic graphing with R](https://reader034.vdocument.in/reader034/viewer/2022042714/554e8332b4c905f66a8b5625/html5/thumbnails/21.jpg)
## baseplot(fn1 ~ age, bone)
## latticexyplot(fn1 ~ age, bone)
## ggplot2qplot(age, fn1, data = bone)
![Page 22: (Very) Basic graphing with R](https://reader034.vdocument.in/reader034/viewer/2022042714/554e8332b4c905f66a8b5625/html5/thumbnails/22.jpg)
Box plot
![Page 23: (Very) Basic graphing with R](https://reader034.vdocument.in/reader034/viewer/2022042714/554e8332b4c905f66a8b5625/html5/thumbnails/23.jpg)
## baseboxplot(Wk12lvl ~ Prepar, vitA)
## latticebwplot(Wk12lvl ~ factor(Prepar), vitA)
## ggplot2qplot(factor(Prepar), Wk12lvl, data = vitA, geom = "boxplot")
![Page 24: (Very) Basic graphing with R](https://reader034.vdocument.in/reader034/viewer/2022042714/554e8332b4c905f66a8b5625/html5/thumbnails/24.jpg)
Grouped plot
![Page 25: (Very) Basic graphing with R](https://reader034.vdocument.in/reader034/viewer/2022042714/554e8332b4c905f66a8b5625/html5/thumbnails/25.jpg)
## baselayout(matrix(1:4,ncol = 2))for (i in 1:4) { plot(Wk12lvl ~ Base1lvl, subset(vitA, Prepar == i)) title(paste("Prepar = ", i))}
## latticexyplot(Wk12lvl ~ Base1lvl | factor(Prepar), vitA)
## ggplot2ggplot(vitA, aes(x = Base1lvl, y = Wk12lvl, group = factor(Prepar))) + geom_point() + facet_wrap(~Prepar)
![Page 26: (Very) Basic graphing with R](https://reader034.vdocument.in/reader034/viewer/2022042714/554e8332b4c905f66a8b5625/html5/thumbnails/26.jpg)