R并排分组箱线图

R并排分组箱线图,r,colors,legend,boxplot,R,Colors,Legend,Boxplot,我有两种植物的气体排放的时间数据,这两种植物都经过了相同的处理。与一些人一起整理此代码[编辑]: soilflux = read.csv("soil_fluxes.csv") library(ggplot2) soilflux$Treatment <- factor(soilflux$Treatment,levels=c("L-","C","L+")) soilplot = ggplot(soilflux, aes(factor(Week), Flux, fill=Species, al

我有两种植物的气体排放的时间数据,这两种植物都经过了相同的处理。与一些人一起整理此代码[编辑]:

soilflux = read.csv("soil_fluxes.csv") 
library(ggplot2)
soilflux$Treatment <- factor(soilflux$Treatment,levels=c("L-","C","L+"))
soilplot = ggplot(soilflux, aes(factor(Week), Flux, fill=Species, alpha=Treatment)) + stat_boxplot(geom ='errorbar') + geom_boxplot()
soilplot = soilplot + labs(x = "Week", y = "Flux (mg m-2 d-1)") + theme_bw(base_size = 12, base_family = "Helvetica")
soilplot
soilflux=read.csv(“土壤通量.csv”)
图书馆(GG2)

soilflux$Treatment作为一种解决方法,您可以从
物种
处理
创建一个组合因子,并手动指定填充颜色:

library(ggplot2)
library(RColorBrewer)
d <- expand.grid(week = factor(1:4), species = factor(c("Heisteria", "Simarouba")),
                 trt = factor(c("C", "L-", "L+"), levels = c("L-", "C", "L+")))

d <- d[rep(1:24, each = 30), ]
d$flux <- runif(NROW(d))

# Create a combined factor for coding the color
d$spec.trt <- interaction(d$species, d$trt, lex.order = TRUE, sep = " - ")

ggplot(d, aes(x = week, y = flux, fill = spec.trt)) +
   stat_boxplot(geom ='errorbar') + geom_boxplot() +
   scale_fill_manual(values = c(brewer.pal(3, "Greens"), brewer.pal(3, "Reds"))) 
库(ggplot2)
图书馆(RColorBrewer)

我倾向于同意将两种尺度混合在一起实际上可能是更好的解决方案。使用离散的alpha值(大于2)与不同的颜色相结合,使眼睛很难比较并找出哪些级别匹配在一起,等等。此外,当双刻度解决方案不匹配时,独特的刻度显示所有可能的颜色组合。非常欢迎您。如果有效,你也能接受答案吗?