(very) basic graphing with r

Post on 10-May-2015

2.009 Views

Category:

Education

1 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Graphingwith

2012-11-19 @HSPHKazuki Yoshida, M.D. MPH-CLE student

FREEDOMTO  KNOW

Group Website is at:

http://rpubs.com/kaz_yos/useR_at_HSPH

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

Menu

n Basic graphing with R

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

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

Open R Studio

lattice ggplot2Install and Load

Read in BONEDEN.DAT.txt

Name it bone

Bone density in twins with discordant smoking exposure

Read in BETACAR.DAT.txt

Name it vitA

Plasma level of carotene by different formula of beta-carotene

Y-axis ~ X-axis

formula

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), Wk12lvl, data = vitA, geom = "boxplot")

Grouped plot

## 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)

top related