## ----style, echo = FALSE, results = 'asis'--------------------------------- knitr::opts_chunk$set( eval=as.logical(Sys.getenv("KNITR_EVAL", "TRUE")), cache=as.logical(Sys.getenv("KNITR_CACHE", "TRUE"))) ## ----search---------------------------------------------------------------- search() ## -------------------------------------------------------------------------- library("survival") ## ----eval=FALSE------------------------------------------------------------ # library(help="survival") # ls(2) ## ----eval=FALSE------------------------------------------------------------ # install.packages("ggplot2", repos="https://cran.r-project.org") ## ----eval=FALSE------------------------------------------------------------ # BiocInstaller::biocLite("ggplot2") ## ----echo=FALSE------------------------------------------------------------ path <- system.file(package="BiocIntro", "extdata", "BRFSS-subset.csv") brfss <- read.csv(path) ## ---- eval=FALSE----------------------------------------------------------- # path <- file.choose() # or file.path # brfss <- read.csv(path) ## -------------------------------------------------------------------------- brfss$Year <- factor(brfss$Year) ## -------------------------------------------------------------------------- brfss2010Male <- subset(brfss, (Year == 2010) & (Sex == "Male")) fit <- lm(Weight ~ Height, brfss2010Male) plot(Weight ~ Height, brfss2010Male, main="2010, Males") abline(fit, lwd=2, col="blue") points(180, 90, pch=20, cex=3, col="red") ## -------------------------------------------------------------------------- brfssFemale <- subset(brfss, Sex=="Female") opar = par(mfrow=c(2, 1)) # layout: 2 'rows' and 1 'column' hist( # first panel -- 1990 brfssFemale[ brfssFemale$Year == 1990, "Weight" ], main = "Female, 1990") hist( # second panel -- 2010 brfssFemale[ brfssFemale$Year == 2010, "Weight" ], main = "Female, 2010") par(opar) # restore original layout ## -------------------------------------------------------------------------- library(ggplot2) ## ---- warning=FALSE-------------------------------------------------------- ggplot(brfss2010Male, aes(x=Height, y=Weight)) + geom_point() + geom_smooth(method="lm") ## ---- warning=FALSE-------------------------------------------------------- plt <- ggplot(brfss2010Male, aes(x=Height, y=Weight)) + geom_point() + geom_smooth(method="lm") plt + labs(title = "2010 Male") ## ---- warning=FALSE-------------------------------------------------------- ggplot(brfssFemale, aes(x=Height, y=Weight)) + geom_point() + geom_smooth(method="lm") + facet_grid(. ~ Year) ## ---- warning=FALSE-------------------------------------------------------- ggplot(brfssFemale, aes(Weight, fill=Year)) + geom_density(alpha=.2)