我想增加 y Axis 标签和 Axis 编号之间的距离(在示例中:“高度”和“1.5”之间有更多空间),并且 Axis 标签左侧也有更多空间。
改变mar
和oma
在par
不执行任何操作。一些类似的问题here和 here ,但因为他们没有可重现的例子,所以它没有解决我的问题。我没有使用任何软件包。
这是我的代码:
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()
改变mar
和oma
不执行任何操作并生成完全相同的图!
图1
图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))
绘图如下所示:
关于r - 使用 par mar 和 oma 增加 png 图中的边距不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62925798/