4

I’m trying to create bar plots paneled by building. For readability I want to create a separate graph for each set of four buildings. I would like the widths of the bars to be the same across all plots.

I’ve tried using the width command. This works to adjust the width within a particular plot but is not keeping the width uniform across plots. Is appears as if there is an overwrite function that fixes the width based on the number of values of the variable Final. Does anyone know to fix the width so that it is the same across plots?

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")
gkcn
  • 1,360
  • 1
  • 12
  • 23
Ani
  • 313
  • 2
  • 11
  • I _think_ that the underlying issue here is that the bar width in the 4 panel plot is being scaled down along with the size of each panel. If you have horizontal bars, try scaling the width in the single panel plot (`p2`) by 2, (i.e. `width = 0.2`). Does that look ok to you? – joran Aug 14 '13 at 18:44

0 Answers0