保存到文件后,情节被切断了

时间:2015-04-17 15:21:26

标签: r plot legend par

我的无花果在情节之外有一个很大的传说。 6条长描述的线条当我保存它时,图例不会显示。我调整了标准杆,但它仍然不起作用。

legend("topright", inset=c(-0.6,0),xpd=TRUE,cex=0.8,
+legend=c("A_all peaks","B_ from all peaks","C_from all peaks","A_from unique peaks",
+"B_from unique peaks","C_from unique peaks",
+"A_from overlap peaks","B_from overlap peaks","C_from overlap peaks"),
+col=c("green","red","blue","lightgreen","pink","lightblue","darkgreen","darkred","steelblue"),
+pch=c(20,20,20,20,20,20,20,20,20),bty="n")

> par()$oma
[1] 2 2 2 2 
> par()$mar
[1] 5.1 4.1 4.1 8.0

当保存宽度较长(尝试800,1000像素)时,没有传说显示。但是,当短宽度()时,部分传奇显示。这真的让我很困惑。第一张图是500 * 333,第二张图是500 * 800。

enter image description here enter image description here

3 个答案:

答案 0 :(得分:0)

不确定你是如何将剧情保存到文件中的,但我通常的惯例是通过常规手段在R中制作漂亮的情节:

plot(blah,blah,blah)
legend(blah,blah,blah)

然后,一旦我对R控制台图形的外观感到满意,我会使用pdf()或其中一个表兄(jpeg()tiff()等)来保存它要归档,确保设置宽度和高度参数如下:

# set up plotting device
pdf( {{FileName}}, 
   width = par('din')[1],
   height = par('din')[2])

plot(blah,blah,blah)
legend(blah,blah,blah)

# disconnect the plotting device
dev.off()

答案 1 :(得分:0)

使用png()tiff()保存它:

tiff("filename",

<code for plot>,
height=5,width=7)
dev.off()

答案 2 :(得分:0)

绘图后,尝试

% your code…

dev.copy(pdf, 'yourfile.pdf')
dev.off()

来自https://statistics.berkeley.edu/computing/saving-plots-r