Bars in geom_bar have unwanted different widths when using facet_wrap

后端 未结 2 2090
借酒劲吻你
借酒劲吻你 2020-12-01 22:02

I can\'d find a solution for the following problem(s). I would appreciate some help a lot!

The following code produces bar charts using facet. However, due to \"extr

2条回答
  •  庸人自扰
    2020-12-01 22:09

    Here what I did after suggestion from Gregor. Using geom_segment and geom_point makes a nice graph as I think.

    library(ggplot2)
    
    all<-read.xls('all_auto_visual_c.xls')
    
    all$station<-as.factor(all$station)
    all$group.new<-factor(all$group, levels=c('C. hyperboreus','C. glacialis','Combined','M. longa','Pseudocalanus sp.','Copepoda'))
    all$shortname2.new<-factor(all$shortname2, levels=c('All','F','M','C5','C4','C3','C2','C1','Micro',     'Oith','Tric','Cegg','Cnaup','C3&2','C2&1'))
    
    allp<-ggplot(all, aes(x=perc_correct, y=shortname2.new)) +
      geom_segment(aes(yend=shortname2.new), xend=0, colour="grey50") +
      geom_point(size=4, aes(colour=sample_size)) +
      scale_colour_gradient("Sample size (n)",low="lightblue",high="navyblue") +
      geom_text(aes(label = perc_correct, hjust = -0.5)) +
      theme_bw() +
      theme(panel.grid.major.y = element_blank()) +
      facet_grid(group.new~station,scales="free_y",space="free") +
      xlab("Automatic identification and visual validation concur (%)") + ylab("Species and stages")+
      ggtitle("Visual validation of predictions")+
      theme_bw() + 
      theme(plot.title = element_text(lineheight=.8, face="bold", size=20,vjust=1), axis.text.x = element_text(colour="grey20",size=12,angle=0,hjust=.5,vjust=.5,face="bold"), axis.text.y = element_text(colour="grey20",size=12,angle=0,hjust=1,vjust=0,face="bold"), axis.title.x = element_text(colour="grey20",size=15,angle=0,hjust=.5,vjust=0,face="bold"), axis.title.y = element_text(colour="grey20",size=15,angle=90,hjust=.5,vjust=1,face="bold"),legend.position="none", strip.text.x = element_text(size = 12, face="bold", colour = "black", angle = 0), strip.text.y = element_text(size = 8, face="bold", colour = "black"))
    
    allp
    
    ggsave(allp, file="auto_visual_no_label.jpeg", height= 11, width= 8.5, dpi= 400,)
    

    This is what it produces!

    enter image description here

提交回复
热议问题