Graphing  with 2012-11-19 @HSPHKazuki Yoshida, M.D.  MPH-CLE student                       FREEDOM                       T...
Group Website is at:http://rpubs.com/kaz_yos/useR_at_HSPH
Previously in this groupn   Introductionn   Reading Data into R (1)n   Reading Data into R (2)n   Descriptive, continu...
Menun   Basic graphing with R
Ingredients          Statistics                  Programmingn   One-variable plot         n   base, lattice, and ggplot2...
3 different systems
base (traditional)        http://commons.wikimedia.org/wiki/File:Plottype.png
lattice package    http://zoonek.free.fr/blosxom/R/2006-08-10_R_Graphics.html
ggplot2http://blog.revolutionanalytics.com/2009/09/ggplot2-and-the-grammar-of-graphics.html
OpenR Studio
Install and Load lattice ggplot2
Download comma-separated and Excel Put them in folderBONEDEN.DAT.txtBETACAR.DAT.txt        http://www.cengage.com/cgi-wads...
Read in BONEDEN.DAT.txt       Name it bone Bone density in twins withdiscordant smoking exposure
Read in BETACAR.DAT.txt            Name it vitAPlasma level of carotene by different     formula of beta-carotene
formula    Y-axis ~ X-axis
Histogram
## basehist(bone$age)## latticehistogram(bone$age)## ggplot2qplot(x = age, data = bone, geom = "Histogram")
Density plot
## baseplot(density(bone$age))## latticedensityplot(bone$age)## ggplot2qplot(x = age, data = bone, geom = "density")
Scatter plot
## baseplot(fn1 ~ age, bone)## latticexyplot(fn1 ~ age, bone)## ggplot2qplot(age, fn1, data = bone)
Box plot
## baseboxplot(Wk12lvl ~ Prepar, vitA)## latticebwplot(Wk12lvl ~ factor(Prepar), vitA)## ggplot2qplot(factor(Prepar), Wk12...
Grouped plot
## baselayout(matrix(1:4,ncol = 2))for (i in 1:4) {      plot(Wk12lvl ~ Base1lvl, subset(vitA, Prepar == i))      title(pa...
(Very) Basic graphing with R
Upcoming SlideShare
Loading in...5
×

(Very) Basic graphing with R

2,074

Published on

Published in: Education
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,074
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
28
Comments
0
Likes
3
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? fid=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)
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×