4

似乎标题周围有一些填充物,我不知道如何更改,有什么想法吗?

xy <- data.frame(x=1:10, y=10:1)
plot <- ggplot(data = xy)+ geom_point(aes(x = x, y =  y))
plot <- plot + opts(plot.background = theme_rect(colour = 'purple', fill = 'pink', size = 3, linetype='dashed'))
plot
plot + opts(title = 'Graph Title')
plot

如果你运行这个,在你的屏幕上放一张纸(老派,我知道)与标题中 G 和 T 的顶部对齐,然后再次运行这个情节,你会看到你的上方有一些灰色纸。我只能认为这表明标题周围有一些填充?或者同样地,如果你在没有标题的情况下运行它并将纸张(上方)与粉红色背景的末端对齐,然后在标题的情况下运行它,G 和 T 的顶部在纸张下方。

示例本质上来自https://github.com/hadley/ggplot2/wiki/Graph-Panel-Attributes

这表明有一个行高选项,但它似乎什么也没做http://www.inside-r.org/packages/cran/ggplot2/docs/theme_text

4

1 回答 1

3

所以这是一个黑客:

p <- plot + opts(title = 'Graph Title')
p <- ggplot_gtable(ggplot_build(p))
p$heights[[2]] <- p$heights[[2]]-unit(0.5, "lines")
grid.draw(p)

此代码删除填充。

但我建议发送功能请求:https ://github.com/hadley/ggplot2/issues?milestone=

于 2012-04-26T08:55:30.573 回答