Reputation: 27
I have constructed a nice looking boxplot in r for data looking at the production of methane under different incubation temperatures. The plot looks at the production of CH4 by the patch from which the sample was collected.
However there is a temperature variable. Samples were split with 50% incubated at 10* and 50% at 26*
This is my current plot:
Methanogenesis_Data=read.csv("CO2-CH4 Rates.csv")
attach(Methanogenesis_Data)
summary(Methanogenesis_Data)
str(Methanogenesis_Data)
boxplot(CH4rate~Patch, data = Methanogenesis_Data, xlab="Patch",
ylab="CH4 µmol g-1 hr-1 ",
col=c("lightblue","firebrick1"), main = "CH4 Production After
Incubation", frame.plot=FALSE)
This was my previous plot:
boxplot(CH4rate~Patch+Temperature, data = Methanogenesis_Data,
xlab="Patch", ylab="CH4 µmol g-1 hr-1 ",
col=c("lightblue","firebrick1"), main = "CH4 Production After
Incubation", frame.plot=FALSE)
Here is the data:
structure(list(Patch = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("Gravel", "Macrophytes",
"Marginal"), class = "factor"), Temperature = structure(c(2L,
2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 1L, 1L,
1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L), .Label = c("Cold",
"Warm"), class = "factor"), CH4rate = c(0.001262595, 0.00138508,
0.001675944, 0.001592354, 0.002169233, 0.001772964, 0.002156633,
0.002864403, 0.002301383, 0.002561042, 0.005189598, 0.004557227,
0.008484851, 0.006867866, 0.007438633, 0.005405327, 0.006381582,
0.008860084, 0.007615417, 0.007705906, 0.009198508, 0.00705233,
0.007943024, 0.008319768, 0.010362114, 0.007822153, 0.010339339,
0.009252302, 0.008249555, 0.008197657), CO2rate = c(0.002274825,
0.002484866, 0.003020209, 0.00289133, 0.003927232, 0.003219346,
0.003922613, 0.005217026, 0.00418674, 0.00466427, 0.009427322,
0.008236453, 0.015339532, 0.012494729, 0.013531303, 0.009839847,
0.011624428, 0.016136746, 0.0138831, 0.014051034, 0.016753211,
0.012780956, 0.01445912, 0.01515584, 0.01883252, 0.014249452,
0.018849478, 0.016863299, 0.015045964, 0.014941168)), .Names =
c("Patch",
"Temperature", "CH4rate", "CO2rate"), class = "data.frame", row.names =
c(NA,
-30L))
What I am attempting to do is have my current plot, but with boxes in the boxplot representing both warm and cold temperatures within the 3 Patch areas. Boxplot of CH4 production by Patch inc. Temp <--- This is what I want to do!
Thank You for any assistance!!
Upvotes: 1
Views: 49
Reputation: 1800
You could try it using ggplot2:
library(tidyverse)
Methanogenesis_Data %>%
ggplot(aes(x = Patch, y = CH4rate, fill = Temperature)) +
geom_boxplot() +
scale_fill_manual(values = c("lightblue","firebrick1")) +
scale_x_discrete(drop = F) +
theme_minimal()+
labs(y = 'CH4 µmol g-1 hr-1', title = "CH4 Production After Incubation")
Or, if you so wish, try it with base-R:
boxplot(CH4rate~Temperature + Patch, data = Methanogenesis_Data, xlab="Patch",
ylab="CH4 µmol g-1 hr-1 ",
col=c("lightblue","firebrick1"), main = "CH4 Production After
Incubation", frame.plot=FALSE,xaxt = 'n')
legend('topleft', legend = c('cold', 'warm'), fill = c("lightblue","firebrick1"))
axis(1,at = c(1.5,3.5,5.5), labels = levels(Methanogenesis_Data$Patch))
Upvotes: 2