Я пытаюсь создать barplot, используя 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))
Я хотел бы создать barplot, где 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")
Но не оба! Спасибо всем, кто может дать совет.