简体   繁体   English

如何在 PDF 中导出带有文字和图例的 plot?

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

When I try to export a plot in PDF, all the text (titles, axis…) and the legend disappear.当我尝试在 PDF 中导出 plot 时,所有文本(标题、轴……)和图例都消失了。 Exporting the plot as a PNG works.将 plot 导出为 PNG 作品。

I just use the “Export ▾” button in the plot panel.我只是使用 plot 面板中的“导出▾”按钮。

Is there a way to keep the legend and text on the PDF?有没有办法保留 PDF 上的图例和文字? An additionnal package maybe?也许还有一个额外的 package?

Thank you and have a good day!谢谢你,有一个美好的一天!

Here is a simple way to export plots to PDF. You simply use the functions "pdf()" and "dev.off()".这是将绘图导出到 PDF 的简单方法。您只需使用函数“pdf()”和“dev.off()”。 It can handle multiple plots and can be used in loops to generate many pages of plots.它可以处理多个图,并且可以在循环中使用以生成多页图。

#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 from http://www.sthda.com/english/wiki/add-legends-to-plots-in-r-software-the-easiest-way 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