我有一个数据集,我试图将其绘制为构面中的分组列,列大小相同。
数据集:
天=代表(1:6,次=15)
颜色=c("黄色","黄色","黄色","黄色","黄色","黄色","红色","红色","红色","红色","红色","红色", "绿色","绿色","绿色","绿色","绿色","绿色", "黄色", "黄色","黄色","黄色","黄色","黄色", “红色”、“红色”、“红色”、“红色”、“红色”、“红色”、“绿色”、“绿色”、“绿色”、“绿色”、“绿色”、“绿色”、“蓝色” ","蓝色","蓝色","蓝色","蓝色","蓝色","紫色","紫色","紫色","紫色","紫色","紫色”、“黄色”、“黄色”、“黄色”、“黄色”、“黄色”、“黄色”、“红色”、“红色”、“红色”、“红色”、“红色”、“红色” , "绿色","绿色","绿色","绿色","绿色","绿色", "黄色", "黄色","黄色","黄色","黄色","黄色", "红色”、“红色”、“红色”、“红色”、“红色”、“红色”、“绿色”、“绿色”、“绿色”、“绿色”、“绿色”、“绿色”、“黄色” , "黄色","黄色","黄色","黄色","黄色")黄色”、“黄色”、“黄色”、“红色”、“红色”、“红色”、“红色”、“红色”、“红色”、“绿色”、“绿色”、“绿色”、“绿色” “绿色”、“绿色”、“黄色”、“黄色”、“黄色”、“黄色”、“黄色”、“黄色”、“红色”、“红色”、“红色”、“红色”、红色”、“红色”、“绿色”、“绿色”、“绿色”、“绿色”、“绿色”、“绿色”、“黄色”、“黄色”、“黄色”、“黄色”、“黄色” ,“黄色的”)黄色”、“黄色”、“黄色”、“红色”、“红色”、“红色”、“红色”、“红色”、“红色”、“绿色”、“绿色”、“绿色”、“绿色” “绿色”、“绿色”、“黄色”、“黄色”、“黄色”、“黄色”、“黄色”、“黄色”、“红色”、“红色”、“红色”、“红色”、红色”、“红色”、“绿色”、“绿色”、“绿色”、“绿色”、“绿色”、“绿色”、“黄色”、“黄色”、“黄色”、“黄色”、“黄色” ,“黄色的”)“绿色”、“绿色”、“绿色”、“绿色”、“绿色”、“黄色”、“黄色”、“黄色”、“黄色”、“黄色”、“黄色”、“红色”、“红色” ","红","红","红","红","绿","绿","绿","绿","绿","绿","黄","黄", "黄色","黄色","黄色","黄色")“绿色”、“绿色”、“绿色”、“绿色”、“绿色”、“黄色”、“黄色”、“黄色”、“黄色”、“黄色”、“黄色”、“红色”、“红色” ","红","红","红","红","绿","绿","绿","绿","绿","绿","黄","黄", "黄色","黄色","黄色","黄色")绿色”、“绿色”、“绿色”、“绿色”、“绿色”、“黄色”、“黄色”、“黄色”、“黄色”、“黄色”、“黄色”)绿色”、“绿色”、“绿色”、“绿色”、“绿色”、“黄色”、“黄色”、“黄色”、“黄色”、“黄色”、“黄色”)
值=rep(c(9,8,7,6,5,8,7,6,5,4,7,6,5,4,3), times=6)
Fruit=rep(c("CApple", "Banana", "ABlueberry","Mango", "Melon", "Pear"), times = c(18,18,12,18,18,6))
数据 <-data.frame(Day, Fruit, Colour, Values) %>%
mutate(unten=Values-0.2, oben=Values+0.2)
我的代码是:
ForPlot <- ggplot(Data, aes(Colour, Values), fill=Colour)
design <- theme(strip.background = element_blank(),
panel.background = element_blank(),
panel.grid.major = element_blank(),
strip.placement = "outside",
panel.border=element_blank(),
# axis.line = element_line(colour = "black"),
axis.line.x = element_line(colour = "white"),
axis.ticks.x=element_blank(),
legend.title = element_blank(),
# axis.text=element_text(size=8),
axis.text.x=element_blank(),
axis.title=element_text(size=10),
strip.text = element_text(size = 10))
ForPlot+
geom_hline(yintercept = c(0, 2.5, 5, 7.5, 10), colour= "lightgrey" )+
geom_col(aes(fill=Colour),
position=position_dodge2(preserve="single"))+
ggtitle("Fruity Colours")+
ylab("Values") + xlab("Day") +
facet_wrap(~Fruit, scales= "free", ncol=3)+
scale_y_continuous()+
scale_fill_discrete()+
geom_text(aes(label = Day), position=position_dodge2(width= 0.9),
y=-0.2, size=2.4) +
geom_errorbar(aes(ymin=pmax(0,unten), ymax=oben),
position=position_dodge2())+
design+
geom_segment(aes(x=0.4,xend=Inf, y=0, yend=0), color="black")+
geom_segment(aes(x=0.4,xend=0.4, y=0, yend=Inf), colour="black")
目前,不同刻面中的条都具有不同的宽度。我尝试使用“width =”来调整问题,但没有成功(条形图仅相对于其当前大小缩小,或者我丢失了 Day 标签和误差线)。
帮助表示赞赏!