在ggplot2(version> = 0.9.0)中增加axis.title和axis.text之间的空间

前端之家收集整理的这篇文章主要介绍了在ggplot2(version> = 0.9.0)中增加axis.title和axis.text之间的空间前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我目前正在使用github的最新版本的ggplot2。

在0.8.9版本中,我可以做以下操作来增加axis.title和axis.text之间的空间:

之前:

ggplot(diamonds,aes(clarity)) + geom_bar() + opts(
    axis.title.x = theme_text(vjust=-1.1)
)

固定:

ggplot(diamonds,aes(clarity)) + geom_bar() + opts(
    axis.title.x = theme_text(vjust=-1.1),plot.margin = unit(c(1,1,0.8,0.5),"lines")
)

axis.title变得完全可见。

在ggplot2的最新github版本中,plot.margin对axis.title没有影响:

ggplot(diamonds,aes(clarity)) + geom_bar() + opts(
    axis.title.x = theme_text(vjust=-0.2),2,"lines"))

(注意增加底部边距 – 我不能得到plot.background在最新的开发版本中工作)

似乎0.8.9允许axis.title移动由plot.margin创建的额外空间,但这不是最新开发版本中允许的。

在最新的开发版本中是否有新的方法完成此任务(或快速修复)?

任何帮助赞赏。

解决方法

我正在结束这个问题,因为我现在所做的修正似乎成为现在(见下文)。

我在plot-render.r中找到以下代码:64:

xlab_height <- grobHeight(xlabel) + 
  if (is.null(labels$x)) unit(0,"lines") else unit(0.5,"lines")
plot_table <- gtable_add_rows(plot_table,xlab_height)
plot_table <- gtable_add_grob(plot_table,xlabel,name = "xlab",l = panel_dim$l,r = panel_dim$r,t = -1)

ylab_width <- grobWidth(ylabel) + 
  if (is.null(labels$y)) unit(0,"lines")
plot_table <- gtable_add_cols(plot_table,ylab_width,pos = 0)
plot_table <- gtable_add_grob(plot_table,ylabel,name = "ylab",l = 1,b = panel_dim$b,t = panel_dim$t)

我改为:

xlab_height <- grobHeight(xlabel) + 
  if (is.null(labels$x)) unit(0,t = -1,clip = "off") <---- here

ylab_width <- grobWidth(ylabel) + 
  if (is.null(labels$y)) unit(0,t = panel_dim$t,clip = "off") <---- here

这允许使用hjust / vjust结合plot.margin来移动axis.titles而不会剪切。

根据要求,我填写了这个github错误

猜你在找的HTML相关文章