4

我正在尝试创建由建筑物组成的条形图。为了便于阅读,我想为每组四个建筑物创建一个单独的图表。我希望所有地块的条形宽度都相同。

我试过使用宽度命令。这可以调整特定绘图内的宽度,但不能保持绘图间的宽度均匀。看起来好像有一个覆盖函数,它根据变量 Final 的值的数量来固定宽度。有谁知道固定宽度以使其在不同的地块中相同?

library(ggplot2)
building <- c(1,1,1,2,5,4,5,4,2,3,1,4,3,5,5)
Final       <- c("Developing","Developing","Developing","Skilled","Skilled","Skilled","Skilled","Skilled","Skilled","Skilled","Skilled","Skilled","Skilled","Accomplished","Accomplished")
mydata <- data.frame(building,Final)
str(mydata)

sub1 <- subset(mydata, building <= 4)
sub2 <- subset(mydata, building == 5)

p1 <- ggplot(sub1, aes(Final)) + 
  geom_bar(aes(fill=Final),position="dodge",colour="black",width=0.4) + 
  facet_wrap( ~ building,ncol=2) + coord_flip()
p1  + xlab("Final Summative Rating") +   
  scale_x_discrete(labels = c("","","","")) + 
  scale_fill_manual(
    values=c("Ineffective" ="red2","Developing" ="darkgoldenrod2",
             "Skilled" =  "olivedrab3","Accomplished"= "springgreen3")) + 
  theme(strip.text.x = element_text(size = 7.5)) + 
  ylab("Teacher Count") + 
  labs(fill = "Rating")

p2 <- ggplot(sub2, aes(Final)) + 
  geom_bar(aes(fill=Final),position="dodge",colour="black",width=0.4) + 
  facet_wrap( ~ building,ncol=2) + coord_flip()
p2  + xlab("Final Summative Rating") +   
  scale_x_discrete(labels = c("","","","")) + 
  scale_fill_manual(values=c("Ineffective" ="red2","Developing" ="darkgoldenrod2",
                             "Skilled" =  "olivedrab3","Accomplished"= "springgreen3")) + 
  theme(strip.text.x = element_text(size = 7.5)) + 
  ylab("Teacher Count") + labs(fill = "Rating")
4

0 回答 0