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

Q1: Inspect the CO2 dataset. Does this dataset contain missing data? Include the code you used to check in the box. Why is it important to always check for missing data before running statistics in R?

# no it does not contain missing data. And it is important to check for missing data that way we can exclude it from our selection.

Q2: Your boss at the EPA is thrilled with your R skills! There is an international conference coming up and you need to produce two graphs from the CO2 dataset ASAP. Present the code and first six lines of output for both subsets in the box below.

HINT: the | symbol means ‘or’. This may be useful in your answer!

Subset 1 Criteria: Your boss wants the chilled vs nonchilled data for uptake in the CO2 dataset. This dataset should only contain Quebec data where conc are greater than or equal to 675.

head (CO2) #code and **first six lines of output** 
##   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

Subset 2 Criteria: You boss wants the Quebec vs Mississippi data for uptake in the CO2 dataset. This dataset should only include chilled treatments only where conc equal to 250.

Criteria2 <- subset(CO2, conc == 250)
Criteria3 <- subset(Criteria2, Treatment == "chilled")
head (Criteria3)
##    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

Q3: Using the plotting gizmo, properly plot subset 1 and subset 2 from above. Present the code and graphs below. Be sure to add a figure caption explaining the graphs.

#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 <- Criteria2$Treatment
xLabel <- "Treatment"
yData <- Criteria2$uptake
yLabel <- "uptake"
myTitle <- "CO2"
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: WRITE CAPTION HERE.

Figure 1: WRITE CAPTION HERE.

remove(temp.df, meansErrBars.df, graphIT, limits, dodge, fontSize, myTitle, xData, xLabel, yData, yLabel) #clean up
Figure 2: WRITE CAPTION HERE.

Figure 2: WRITE CAPTION HERE.

Please turn–in your homework via Sakai by saving and submitting an R Markdown PDF or HTML file from R Pubs!