避免 R 中的轴标签重叠
我想在图表中绘制数据,并使用较大的标签字体。
x = c(0:10)
y = sin(x) + 10
plot (
x, y, type="o",
xlab = "X values",
ylab = "Y values",
cex.axis = "2",
cex.lab = "2",
las = 1
)
不幸的是,y 轴上的数字与 y 轴的标签重叠。我尝试使用 mar,但这不起作用(顺便问一下,我如何找出哪些图形参数可以直接在绘图命令中使用以及哪些必须使用 par() 方法设置?)。
如何避免标签重叠?
感谢您的帮助。
斯文
I want to plot data in a graph with larger font-size for the lables.
x = c(0:10)
y = sin(x) + 10
plot (
x, y, type="o",
xlab = "X values",
ylab = "Y values",
cex.axis = "2",
cex.lab = "2",
las = 1
)
Unfortunately the numbers on the y-axis overlap the label for the y-axis. I tried to use mar, but that did not work (By the way, how can I find out which graphic parameters can be directly used in the plot command and which have to be set with the par()-method? ).
How can I avoid that labels overlap?
Thanks for your help.
Sven
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用
par(mar)
增加绘图边距,使用par(mgp)
移动轴标签。在帮助页面
?par
中,它解释了哪些参数可以直接在plot
中使用,哪些参数必须通过par
调用。Use
par(mar)
to increase the plot margins andpar(mgp)
to move the axis label.In the help page
?par
it explains which parameters can be used directly inplot
and which must be called viapar
.快速而肮脏的方法是使用
par
并在ylab
中添加换行符,尽管它在概念上很糟糕。关于可以直接在
plot
中设置哪些参数,请查看?plot.default
和?plot.xy
因为它们将收到...
参数。还有一些对未记录函数的调用(据我所知),例如 localWindow 和 localBox,但我不知道它们会发生什么。我猜他们只是被忽略了。The quick and dirty way would be to use
par
and add a newline inylab
, even though it's conceptually terrible.Concerning which parameters you can set directly in
plot
have a look at?plot.default
and?plot.xy
as they will recieve the...
arugments. There's also a couple of calls to undocumented functions (as far as I can find) likelocalWindow
andlocalBox
but I don't know what happens to them. I'd guess they're just ignored.您可以将 mgp 参数放入 title() 函数中,以避免随后重置默认值。这样,参数仅作用于函数添加的标签。像这样:
You can put the mgp parameter into the title() function to avoid having to reset your defaults afterwards. That way the parameter only acts on the label(s) added by the function. like this: