I am currently doing some variable exploration and have generated box plots for 3 different climate parameters (Tmin,Tmean,Tmax) I would like to know how to group those variables in one single box plot with a structure similar to this:
I've seen a couple tutorials online but they all require the grouping parameter to be assigned in the rows of the data frame not the head of the column. I tried adding +tmax as an argument inside tmin but that yielded errors. The code I have used to generate mine are is the following:
tmin<- ggplot(prism, aes(x = factor(season, levels=c("spring","summer","fall","winter")),
y = tmin_c)) +
geom_boxplot(fill = fill, colour = line, alpha = 0.7) +
theme_bw() +
scale_y_continuous(name = "Temperature C") +
scale_x_discrete(name = "Season") +
ggtitle("MRL Temperature 1980-2013") +
theme(plot.title = element_text(hjust = 0.5))
tmin
Solved, here is the final working output for future refrence:
#Temperature
dat <- prism
dat <- dat %>%
select(1,2,4,5,6) #1year,2season,4tmin,5tmean,6tmax
dat <- reshape2::melt(dat, measure.vars=3:5)
ggplot(dat, aes(y = value,
x = factor(season, levels=c("spring","summer","fall","winter")),
fill=factor(variable))) +
geom_boxplot() +
theme_bw() +
scale_y_continuous(name = "Temperature C") +
scale_x_discrete(name = "Season") +
ggtitle("MRL Temperature 1980-2013") +
theme(plot.title = element_text(hjust = 0.5))