2012-05-21 47 views
3

有没有办法在R plot中为y轴创建多行标签?plot中的多行y标签

我曾尝试加入\n其中换行符是应该的,但随后的标签的第一行被剪掉:

l <- 10 
plot(0:l, (0:l), type='l', 
    yaxt='n', 
    xlab='Index', 
    ylab='Cumulative sum\nof the sorted weights') 

Result of plot

出现这种情况既与tikzDevice和内部RStudio。另外,我尝试了一些没有运气的par()选项。如何正确地做到这一点?

(超大UPER保证金困扰我,太...)

回答

9

你需要使用marmgp设置页边距:

l <- 10 
op <- par(mar=c(5, 6, 4, 2) + 0.1) 
plot(0:l, (0:l), type='l', 
    yaxt='n', 
    xlab='Index', 
    ylab='Cumulative sum\nof the sorted weights') 
par(op) 

enter image description here

+0

我试图在调用'plot'时同时使用'mar'和'mgp'。这是为时已晚? – krlmlr

+0

你能详细说明一下吗? “太晚了”是什么意思? – smillig

+0

我正在寻找当我在'plot'调用中使用它们时,边缘参数未被识别的原因。我没有像你的代码那样尝试'par'。 – krlmlr

1

像@smillig建议,你使用par来更改参数marmgp

但您必须致电par之前你叫plot