r - 使用 par mar 和 oma 增加 png 图中的边距不起作用

标签 r plot png axis par

我想增加 y Axis 标签和 Axis 编号之间的距离(在示例中:“高度”和“1.5”之间有更多空间),并且 Axis 标签左侧也有更多空间。

改变maromapar不执行任何操作。一些类似的问题herehere ,但因为他们没有可重现的例子,所以它没有解决我的问题。我没有使用任何软件包。

这是我的代码:

Height = c(3.1, 0.4, 0.9, 2.6, 1.4, 2.1)
Diameter = c(1.0, 0.4, 0.8, 1.1, 0.5, 0.4)
size.data = data.frame(Height, Diameter)

par(mfrow = c(1, 1), mar = c(4, 5, 6, 1), oma = c(0.5, 1, 1, 0.5), mgp = c(2.2, 0.7, 0))
png('Figure.1.png', width = 2800, height = 2400, res = 220)
plot(Height ~ Diameter, data = size.data, xaxs = 'i', yaxs = 'i',
ylim = c(0, 3), xlim = c(0, 1.5), bty = 'n', box = FALSE, 
xlab = 'Diameter', ylab = 'Height', cex = 1.3, cex.axis = 1.3, cex.lab = 1.3, cex.main = 1.3,
pch = 21, bg = 'white', las = 1)
#mtext('Height', side = 2, at = 101, line = 1.1, cex = 1.3)
box(bty = 'L')
dev.off()

par(mfrow = c(1, 1), mar = c(4, 10, 6, 1), oma = c(0.5, 4, 1, 0.5), mgp = c(2.2, 0.7, 0))
png('Figure.2.png', width = 2800, height = 2400, res = 220)
plot(Height ~ Diameter, data = size.data, xaxs = 'i', yaxs = 'i',
ylim = c(0, 3), xlim = c(0, 1.5), bty = 'n', box = FALSE, 
xlab = 'Diameter', ylab = 'Height', cex = 1.3, cex.axis = 1.3, cex.lab = 1.3, cex.main = 1.3,
pch = 21, bg = 'white', las = 1)
#mtext('Height', side = 2, at = 101, line = 1.1, cex = 1.3)
box(bty = 'L')
dev.off()

改变maroma不执行任何操作并生成完全相同的图!

图1

Figure.1

图2

Figure.2

我尝试使用 mtext 单独设置 y Axis 标签但因为没有足够的边距,我试图更改它,所以它也没有显示。我不确定我缺少什么基本的东西,我感谢任何帮助。

最佳答案

您必须在调用png之后调用par

png('Figure.1.png', width = 2800, height = 2400, res = 220)
par(mfrow = c(1, 1), mar = c(4, 5, 6, 1), oma = c(0.5, 1, 1, 0.5), mgp = c(2.2, 0.7, 0))

并且

png('Figure.2.png', width = 2800, height = 2400, res = 220)
par(mfrow = c(1, 1), mar = c(4, 10, 6, 1), oma = c(0.5, 4, 1, 0.5), mgp = c(2.2, 0.7, 0))

绘图如下所示:

Figure 1

Figure 2

关于r - 使用 par mar 和 oma 增加 png 图中的边距不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62925798/

相关文章:

R检测Blas版本

r - 为 facet_grid/facet_wrap 图的每一行分配唯一的宽度

Java:如何用导入的 PNG 文件替换 "oval"或 "rectangle"图形?

python - 使用 PIL 在 python 上向图像添加透明圆圈

Swift Metal 将 bgra8Unorm 纹理保存到 PNG 文件

r - 将可变长度列表转换为 R 中的矩阵

javascript - markercluster 是否与 leafletProxy() 和选项 iconCreateFunction 一起工作?

嵌套函数的 R 范围规则

r - 在 R 中绘制错误椭圆

r - 随机选择ggtheme