我正在尝试使用创建条形图ggplot2
我通过一个变量进行堆叠并通过另一个变量进行躲避。
这是一个示例数据集:
df=data.frame(
year=rep(c("2010","2011"),each=4),
treatment=rep(c("Impact","Control")),
type=rep(c("Phylum1","Phylum2"),each=2),
total=sample(1:100,8))
我想创建一个条形图,其中x=treatment
, y=total
,堆叠变量为type
躲避的变量是year
。当然我可以选择其中之一:
ggplot(df,aes(y=total,x=treatment,fill=type))+geom_bar(position="dodge",stat="identity")
ggplot(df,aes(y=total,x=treatment,fill=year))+geom_bar(position="dodge",stat="identity")
但两者都不是!感谢任何可以提供建议的人。