这是从rstats subreddit交叉发布的。我见过镜像条或分组条,但没有镜像和分组条。我得到的最接近的是使用“堆叠”,但它似乎不能在x轴上用于负值,而“闪避”偏移应该对齐的相关柱:
示例图:
我需要分别在粉色和蓝色条纹下方的绿色和紫色条纹。有谁知道这个库是否可行?这是我一直在使用的:
<a href="http://example.com/files/myfile.pdf" target="_blank">Download</a>
如果我忽略了现有的答案,我道歉。
答案 0 :(得分:4)
这个怎么样?
library(ggplot2)
library(tidyr)
limits <- aes(ymax = Data$mean + Data$sd, ymin = Data$mean - Data$sd)
Data %>% separate(treatment, c("Type", "Pos")) %>%
ggplot(aes(x = factor(group), y = mean, group = Type, fill = interaction(Pos, Type))) +
geom_bar(stat = "identity", position = position_dodge(0.9), color="#000000") +
geom_errorbar(limits, position = position_dodge(0.9), width = 0.25) +
labs(x = "x", y = "y") +
ggtitle("") +
scale_fill_discrete(name = "Treatment",
labels = c("R-Above","R-Below", "T-Above", "T-Below")) +
theme(panel.grid.major=element_blank(),
panel.grid.minor=element_blank(),
panel.background=element_rect(fill="white"),
panel.border=element_rect(fill=NA,color="black"))