如何摆脱ggplot2阴谋的空白? [英] How to get rid of whitespace in a ggplot2 plot?

查看:210
本文介绍了如何摆脱ggplot2阴谋的空白?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在准备出版物的数字。通过设置 xlab()来省略x标签,但是ggplot2会生成一个空格而不是完全删除标签。如何摆脱空白(在下面的图中用红色矩形标记)?


完整的代码:

  ggplot(data,aes(x = Celltype,y = Mean,fill = factor(Dose),label = p.stars))+ 
geom_bar(stat =identity,position = (=平均值±SEM),统计=同一性,位置= position_dodge(宽度= 0.9),position_dodge(width = 0.9),aes(group = Dose))+
geom_errorbar ,宽度= 0.25)+
geom_text(aes(y =平均值+ SEM),size = 5,position = position_dodge(width = 0.9),hjust = 0.5,vjust = -1)+
xlab ()+
ylab(浓度)+
scale_fill_grey(name =Dose)+
theme_bw()

解决方案使用 theme()删除为x轴分配的空间标题。当你设置 xlab()时,这个标题还有空间。

  + theme(axis.title.x = element_blank())


I'm preparing a figure for a publication. I'm omitting the x label by setting xlab(""), however ggplot2 produces a whitespace instead of completely removing the label. How can I get rid of the whitespace (marked by red rectangle in the plot below)?

The full code:

ggplot(data, aes(x=Celltype, y=Mean, fill=factor(Dose), label=p.stars)) +
  geom_bar(stat = "identity", position = position_dodge(width=0.9), aes(group=Dose)) +
  geom_errorbar(aes(ymin = Mean - SEM, ymax = Mean + SEM), stat = "identity", position = position_dodge(width=0.9), width=0.25) +
  geom_text(aes(y = Mean + SEM), size = 5, position = position_dodge(width=0.9), hjust = .5, vjust = -1) +
  xlab("") +
  ylab("Concentration") +
  scale_fill_grey(name = "Dose") +
  theme_bw()

解决方案

Use theme() to remove space allocated for the x axis title. When you set xlab("") there is still space made for this title.

+ theme(axis.title.x=element_blank())

这篇关于如何摆脱ggplot2阴谋的空白?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆