问题描述
似乎在ggplot中创建堆积条形图时,自动堆积变量是填充。是否可以使用其他任何选项,例如alpha?
我希望能够使用不想堆叠的某个变量指定填充颜色。任何建议表示赞赏!
这是我现在拥有的一些代码。我基本上希望每个小节都通过社区填充,并且将检测/未检测到的检测条堆叠并通过alpha或颜色表示:
library(ggplot2)
dat <- data.frame(c(rep("A",times=6),rep("B",rep("C",rep("D",times=6)),rep(c("Year 1","Year 2","Year 3"),times=2),c(rep("Detect",3),rep("Non-Detect",3)),c(75,52,56.3,25,48,43.7,65.8,56.8,35.7,34.2,43.2,64.3,93.5,92.6,82.9,6.5,7.4,17.1,58.3,50.5,46.4,41.7,49.5,53.6))
colnames(dat) <- c("community","year","detection","percent.value")
ggplot(data=dat,mapping=aes(x=community,y=percent.value,fill = detection)) +
geom_bar(position = "stack",stat = "identity") +
ylab("Frequency")+
facet_wrap(.~year)
Example barplot from code above
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)