【发布时间】:2020-11-05 14:19:38
【问题描述】:
我想增加 y 轴标签和轴号之间的距离(在示例中:“高度”和“1.5”之间有更多空间),并且轴标签左侧也有更多空间。
在par 中更改mar 和oma 没有任何作用。一些类似的问题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 轴标签,但由于没有足够的边距,我试图更改它,它也没有显示。我不确定我缺少什么基本的东西,我很感激任何帮助。
【问题讨论】:
-
来自
par:“每个设备[例如png]都有自己的一组图形参数。”。因此,png重置了par。 -
有道理!感谢您添加此内容。
-
有人被咬过:Set plot margin in png plot device ;)
-
啊,我没有看到那个帖子,因为我没有想到它与 png() 相关。很难找到好的关键字来搜索与 R 相关的问题(以及我发布问题时的标题)。