簡體   English   中英

如何在 PDF 中導出帶有文字和圖例的 plot?

[英]How to export a plot in PDF with the text and the legend?

當我嘗試在 PDF 中導出 plot 時,所有文本(標題、軸……)和圖例都消失了。 將 plot 導出為 PNG 作品。

我只是使用 plot 面板中的“導出▾”按鈕。

有沒有辦法保留 PDF 上的圖例和文字? 也許還有一個額外的 package?

謝謝你,有一個美好的一天!

這是將繪圖導出到 PDF 的簡單方法。您只需使用函數“pdf()”和“dev.off()”。 它可以處理多個圖,並且可以在循環中使用以生成多頁圖。

#set up the pdf as folder path / name.pdf
pdf("C:/Users/xxx/Desktop/plot1.pdf")

# Generate some data
x<-1:10; y1=x*x; y2=2*y1
plot(x, y1, type="b", pch=19, col="red", xlab="x", ylab="y", main = "A title")
# Add a line
lines(x, y2, pch=18, col="blue", type="b", lty=2)
# Add a legend
legend(1, 95, legend=c("Line 1", "Line 2"),
       col=c("red", "blue"), lty=1:2, cex=0.8)

dev.off() #turn off develop

Plot 來自http://www.sthda.com/english/wiki/add-legends-to-plots-in-r-software-the-easiest-way

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM