# Load the CO2 Dataset Now! Answer the questions below.
# Carbon Dioxide Uptake in Grass Plants ####
# The CO2 dataframe is from an experiment on the cold tolerance of the
# grass species Echinochloa crus-galli. The CO2 uptake of six plants
# from Quebec and six plants from Mississippi was measured at
# several levels of ambient CO2 concentration. Half the plants
# of each type were chilled overnight before the experiment.
data("CO2")
head(CO2)## Plant Type Treatment conc uptake
## 1 Qn1 Quebec nonchilled 95 16.0
## 2 Qn1 Quebec nonchilled 175 30.4
## 3 Qn1 Quebec nonchilled 250 34.8
## 4 Qn1 Quebec nonchilled 350 37.2
## 5 Qn1 Quebec nonchilled 500 35.3
## 6 Qn1 Quebec nonchilled 675 39.2
# Important Note: R thinks that the Plant, Type, and Treatment
# columns contain text. Don't forget the quotation marks around
# "text" when subsetting in your homework. It’s important to check for missing data because some of the functions won’t be able to work because they can’t compute the missing data.
mean("CO2")## [1] NA
HINT: the | symbol means ‘or’. This may be useful in your answer!
New<-subset(CO2,Type=="Quebec"& conc>=675)
head(New)## Plant Type Treatment conc uptake
## 6 Qn1 Quebec nonchilled 675 39.2
## 7 Qn1 Quebec nonchilled 1000 39.7
## 13 Qn2 Quebec nonchilled 675 41.4
## 14 Qn2 Quebec nonchilled 1000 44.3
## 20 Qn3 Quebec nonchilled 675 43.9
## 21 Qn3 Quebec nonchilled 1000 45.5
Water<-subset(CO2,Treatment=="chilled"&conc==250)
head(Water)## Plant Type Treatment conc uptake
## 24 Qc1 Quebec chilled 250 30.3
## 31 Qc2 Quebec chilled 250 35.0
## 38 Qc3 Quebec chilled 250 38.1
## 66 Mc1 Mississippi chilled 250 18.1
## 73 Mc2 Mississippi chilled 250 12.3
## 80 Mc3 Mississippi chilled 250 17.9
library(plyr)
library(ggplot2)
xData <- New$Treatment
xLabel <- "Treatment"
yData <- New$uptake
yLabel <- "Uptake (ppb)"
myTitle <- "Quebec Treatment vs Uptake"
fontSize <- 18
temp.df <- data.frame(xData, yData)
temp.df <- na.omit(temp.df)
meansErrBars.df <- ddply(temp.df, c("xData"), summarise, N=sum(yData), mean=mean(yData), sd=sd(yData), se=sd/sqrt(N))
graphIT <- ggplot(data = meansErrBars.df, aes(x = xData, y = mean))
limits <- aes(ymax = meansErrBars.df$mean + meansErrBars.df$se, ymin = meansErrBars.df$mean - meansErrBars.df$se)
dodge <- position_dodge(width = 1)
graph_output <- graphIT +
labs(x = xLabel, y = yLabel, title = myTitle) +
geom_bar(stat = "identity", position = dodge, fill="gray", color = "black") +
geom_errorbar(limits, width = 0.6, stat ="identity", position = dodge, size = 1) +
geom_point(data = temp.df, aes(x = xData, y = yData), position = dodge, size = 8, shape=1) +
theme_classic() + theme(axis.text=element_text(size=fontSize*3.5/4),
axis.title.y=element_text(size=fontSize,face="bold", vjust=1.5),
axis.title.x=element_text(size=fontSize,face="bold", vjust=-0.3),
plot.title = element_text(size=fontSize,face="bold", vjust=1.5),
panel.border = element_rect(colour = "black", fill=NA, size=3))
print(graph_output)remove(temp.df, meansErrBars.df, graphIT, limits, dodge, fontSize, myTitle, xData, xLabel, yData, yLabel) library(plyr)
library(ggplot2)
xData <- Water$Type
xLabel <- "Type"
yData <- Water$uptake
yLabel <- "Uptake (ppb)"
myTitle <- "Mississippi vs Quebec based on Uptake"
fontSize <- 18
temp.df <- data.frame(xData, yData)
temp.df <- na.omit(temp.df)
meansErrBars.df <- ddply(temp.df, c("xData"), summarise, N=sum(yData), mean=mean(yData), sd=sd(yData), se=sd/sqrt(N))
graphIT <- ggplot(data = meansErrBars.df, aes(x = xData, y = mean))
limits <- aes(ymax = meansErrBars.df$mean + meansErrBars.df$se, ymin = meansErrBars.df$mean - meansErrBars.df$se)
dodge <- position_dodge(width = 1)
graph_output <- graphIT +
labs(x = xLabel, y = yLabel, title = myTitle) +
geom_bar(stat = "identity", position = dodge, fill="gray", color = "black") +
geom_errorbar(limits, width = 0.6, stat ="identity", position = dodge, size = 1) +
geom_point(data = temp.df, aes(x = xData, y = yData), position = dodge, size = 8, shape=1) +
theme_classic() + theme(axis.text=element_text(size=fontSize*3.5/4),
axis.title.y=element_text(size=fontSize,face="bold", vjust=1.5),
axis.title.x=element_text(size=fontSize,face="bold", vjust=-0.3),
plot.title = element_text(size=fontSize,face="bold", vjust=1.5),
panel.border = element_rect(colour = "black", fill=NA, size=3))
print(graph_output)remove(temp.df, meansErrBars.df, graphIT, limits, dodge, fontSize, myTitle, xData, xLabel, yData, yLabel) Please turn–in your homework via Sakai by saving and submitting an R Markdown PDF or HTML file from R Pubs!