# 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.
No, this dataset does not have any missing data because when I looked up code “CO2” there were not any ’NAs“. It is important to look for missing data because some functions will not work properly.
HINT: the | symbol means ‘or’. This may be useful in your answer!
quebecnonchilled <- subset(CO2, Type == "Quebec" & conc >=675)
head(quebecnonchilled)
## 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
#Here is my plotting gizmo, copy the whole gizmo and adjust the top bit as needed
# vvvvv adjust these parameters vvvvvv
library(plyr)
library(ggplot2)
xData <- quebecnonchilled$Treatment
xLabel <- "Treatment"
yData <- quebecnonchilled$uptake
yLabel <- "Uptake of CO2"
myTitle <- "Quebecs data"
fontSize <- 18 # Adjust font size
# ^^^^^ adjust these parameters ^^^^^^
# vvvvv leave everything below alone! vvvvvv
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)
Figure 1: Quebec data nonchilled vs chilled.
remove(temp.df, meansErrBars.df, graphIT, limits, dodge, fontSize, myTitle, xData, xLabel, yData, yLabel) #clean up
Figure 2: Mississipi vs Quebecs CO2 concentrations.
Please turn–in your homework via Sakai by saving and submitting an R Markdown PDF or HTML file from R Pubs!