调整绘图区域窗口的大小

调整绘图区域窗口的大小

本文介绍了R ggplot 调整绘图区域窗口的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在调整绘图区域的大小时遇到​​问题.如果您查看以下示例,您将看到 x 轴x"的标签超出绘图窗口/区域的范围,因此不再可见.我试图用

I have problems resizing the plot area. If you look at the following example you will see that the label of the x-axis "x" is out of the range of the plot window/area and therefore not visible any longer. I tried to resize the plot window/area with

dev.new(width=10, height=10)

但这不会增加实际绘图区域外的白色边界的空间.我还将绘图保存为 PDF,希望标签x"会重新出现在 PDF 中,但事实并非如此.

but that does not increase the space of the white boundary outside the actual plot area. I also saved the plot as PDF hoping that the label "x" will reappear in the PDF but that's also not the case.

是否有可能以某种方式增加该特定区域?

Is it somehow possible to increase that particular area?

library(ggplot2)
df <- data.frame(x=1:10, y=1:10)
ggplot(df, aes(x,y)) + geom_point() +
  opts(axis.title.x = theme_text(size = 14, hjust = 0.5, vjust = -5))

推荐答案

要更改可用于轴标签和文本的绘图区域的大小,可以使用

To change the size of the plotting area available for axis labels and text, you can use

opts(plot.margin = unit(c(2, 2, 2, 2), "cm"))

指定绘图每一边的边距大小.

to specify the margin size of each side of the plot.

这篇关于R ggplot 调整绘图区域窗口的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 09:14