我的数据如下所示:
Sample Point N.conc toc
H1 0.2 0.2
H1 0.3 0.3
H1 0.4 0.4
H1 0.3 0.3
H1 0.3 0.3
H1 0.5 0.5
H1 0.5 0.5
H1 0.4 0.4
H1 0.1 0.1
H2 0.4 0.4
H2 0.5 0.5
H2 0.5 0.6
H2 0.4 0.5
H2 0.1 0.1
H2 0.3 0.3
H2 0.4 0.4
H2 0.3 0.3
H2 0.3 0.3
H3 0.4 0.4
H3 0.5 0.8
H3 0.3 0.3
H3 0.2 0.2
H3 0.2 0.2
H3 0.4 0.4
H3 0.3 0.3
H3 0.2 0.2
H3 0.3 0.4
请注意,我使用以下方法读取了您的数据:
df <- read.table(text='Point N.conc toc
H1 0.2 0.2
H1 0.3 0.3
H1 0.4 0.4
H1 0.3 0.3
H1 0.3 0.3
H1 0.5 0.5
H1 0.5 0.5
H1 0.4 0.4
H1 0.1 0.1
H2 0.4 0.4
H2 0.5 0.5
H2 0.5 0.6
H2 0.4 0.5
H2 0.1 0.1
H2 0.3 0.3
H2 0.4 0.4
H2 0.3 0.3
H2 0.3 0.3
H3 0.4 0.4
H3 0.5 0.8
H3 0.3 0.3
H3 0.2 0.2
H3 0.2 0.2
H3 0.4 0.4
H3 0.3 0.3
H3 0.2 0.2
H3 0.3 0.4',header=T)
您可以尝试以下方法:
library(ggplot2)
library(reshape2)
df1 <- melt(df,id.vars=1)
ggplot(df1,aes(x=Point,y=value,fill=variable))+
stat_boxplot(geom="errorbar",
stat_params = list(width = 0.2),
position=position_dodge(width=0.3))+
geom_boxplot(position=position_dodge(width=0.3),width=0.25)+
ylab("mg/l")+xlab("")+labs(fill="")+theme_classic()+
theme(axis.title.y = element_text(angle=0))
请注意,对的大多数调用ggplot()
都是为了获得答案,以更接近地模仿您的绘图。可以通过以下方法获得足够的箱线图:
ggplot(df1,aes(x=Point,y=value,fill=variable))+geom_boxplot()
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句