Upcoming SlideShare
×

# (Very) Basic graphing with R

2,397 views

Published on

Published in: Education
4 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
Your message goes here
• Be the first to comment

Views
Total views
2,397
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
32
0
Likes
4
Embeds 0
No embeds

No notes for slide

### (Very) Basic graphing with R

1. 1. Graphing with 2012-11-19 @HSPHKazuki Yoshida, M.D. MPH-CLE student FREEDOM TO  KNOW
2. 2. Group Website is at:http://rpubs.com/kaz_yos/useR_at_HSPH
3. 3. Previously in this groupn Introductionn Reading Data into R (1)n Reading Data into R (2)n Descriptive, continuousn Descriptive, categorical Group Website: http://rpubs.com/kaz_yos/useR_at_HSPH
4. 4. Menun Basic graphing with R
5. 5. Ingredients Statistics Programmingn One-variable plot n base, lattice, and ggplot2 n Histogram n hist(), histogram() n Density plot n densityplot()n Two-variable plot n plot(Y~X) n Scatter plot n boxplot(), bwplot() n Box plot n Conditioning in latticen Grouped plot
6. 6. 3 different systems
7. 7. base (traditional) http://commons.wikimedia.org/wiki/File:Plottype.png
8. 8. lattice package http://zoonek.free.fr/blosxom/R/2006-08-10_R_Graphics.html
9. 9. ggplot2http://blog.revolutionanalytics.com/2009/09/ggplot2-and-the-grammar-of-graphics.html
10. 10. OpenR Studio
11. 11. Install and Load lattice ggplot2
12. 12. Download comma-separated and Excel Put them in folderBONEDEN.DAT.txtBETACAR.DAT.txt http://www.cengage.com/cgi-wadsworth/course_products_wp.pl? ﬁd=M20bI&product_isbn_issn=9780538733496
13. 13. Read in BONEDEN.DAT.txt Name it bone Bone density in twins withdiscordant smoking exposure
14. 14. Read in BETACAR.DAT.txt Name it vitAPlasma level of carotene by different formula of beta-carotene
15. 15. formula Y-axis ~ X-axis
16. 16. Histogram
17. 17. ## basehist(bone\$age)## latticehistogram(bone\$age)## ggplot2qplot(x = age, data = bone, geom = "Histogram")
18. 18. Density plot
19. 19. ## baseplot(density(bone\$age))## latticedensityplot(bone\$age)## ggplot2qplot(x = age, data = bone, geom = "density")
20. 20. Scatter plot
21. 21. ## baseplot(fn1 ~ age, bone)## latticexyplot(fn1 ~ age, bone)## ggplot2qplot(age, fn1, data = bone)
22. 22. Box plot
23. 23. ## baseboxplot(Wk12lvl ~ Prepar, vitA)## latticebwplot(Wk12lvl ~ factor(Prepar), vitA)## ggplot2qplot(factor(Prepar), Wk12lvl, data = vitA,geom = "boxplot")
24. 24. Grouped plot
25. 25. ## 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)