首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用facet_wrap时,geom_bar中的条具有不需要的不同宽度

使用facet_wrap时,geom_bar中的条具有不需要的不同宽度
EN

Stack Overflow用户
提问于 2015-05-13 00:06:12
回答 1查看 7.4K关注 0票数 11

我可以找到以下问题的解决方案。我将非常感谢一些人的帮助!

下面的代码使用facet生成条形图。然而,由于ggplot2在某些组中有“额外的空间”,即使我指定的宽度为0.1或类似的宽度,它也会使条更宽。我觉得这很烦人,因为这让它看起来很不专业。我希望所有的条看起来都一样(除了填充)。我希望有人能告诉我如何解决这个问题。

其次,如何在facet窗口中对不同的类进行重新排序,使其始终是C1,C2 ...C5、M、F、所有适用的。我尝试了对因子的级别进行排序,但由于并非所有类都存在于每个图部分中,因此它不起作用,或者至少我认为这是原因。

第三,如何减小条之间的间距?这样整个图形就会更加压缩。即使我为了导出而使图像变小,R也会缩小条形图,但条形图之间的间距仍然很大。

我将非常感谢这些答案中的任何一个反馈!

我的数据:http://pastebin.com/embed_iframe.php?i=kNVnmcR1

我的代码:

代码语言:javascript
运行
复制
library(dplyr)
library(gdata)
library(ggplot2)
library(directlabels)
library(scales) 

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','Special Calanus','M. longa','Pseudocalanus sp.','Copepoda'))

allp <- ggplot(data = all, aes(x=shortname2, y=perc_correct, group=group,fill=sample_size)) + 

  geom_bar(aes(fill=sample_size),stat="identity", position="dodge", width=0.1, colour="NA") + scale_fill_gradient("Sample size (n)",low="lightblue",high="navyblue")+
  facet_wrap(group~station,ncol=2,scales="free_x")+

  xlab("Species and stages") + ylab("Automatic identification and visual validation concur (%)") +
  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 = 12, face="bold", colour = "black"))
allp

#ggsave(allp, file="auto_visual_stackover.jpeg", height= 11, width= 8.5, dpi= 400,)

需要修复的当前图形:

非常感谢!

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30196143

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档