[英]R legend outside of graph not showing in pdf
以下代碼應該將以下圖表(圖表外有圖例)導出為 pdf。 但是圖例沒有出現在生成的 pdf 中。 但是,如果我只運行沒有 pdf 行的代碼,則圖例會顯示在 Rstudio 的繪圖查看器中。
pdf(paste("testgraph.pdf", sep=''), paper="a4r", width=10, height=10)
set.seed(1) # just to get the same random numbers
plot(1:30, rnorm(30), pch = 1, lty = 1, type = "o", ylim=c(-2,2), bty='L')
legend("topright", inset=c(-0.3,0),c("group A", "group B"), pch = c(1,2), lty = c(1,2))
dev.off()
這段代碼對你有幫助嗎?
pdf(paste("testgraph.pdf", sep=''), paper="a4r", width=10, height=10)
set.seed(1) # just to get the same random numbers
plot(1:30, rnorm(30), pch = 1, lty = 1, type = "o", ylim=c(-2,2), bty='L')
legend("topright",c("group A", "group B"), pch = c(1,2),lty = c(1,2))
dev.off()
在legend()
設置xpd = TRUE
並使用par(mar = c(c(bottom, left, top, right) + 0.1))
獲得更寬的邊距。 使用 x 和 y 坐標定位您的圖例。
pdf("testgraph.pdf", paper="a4r", width=10, height=10)
par(mar = c(c(5, 4, 4, 6) + 0.1))
set.seed(1) # just to get the same random numbers
plot(1:30, rnorm(30), pch = 1, lty = 1, type = "o", ylim=c(-2,2), bty='L')
legend(x = 31, y = 1, legend = c("group A", "group B"),
pch = c(1,2), lty = c(1,2), xpd = TRUE)
dev.off()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.