我嘗試保存不同角度的圖(以后想在投影儀中使用它來制作影片)。我試過這個:
data=data.frame(x=rnorm(100)) # creates the data
plot <- ggplot2::qplot(x, data=data, geom="histogram") # create a histogram
for(i in seq(-90, 0, by = 30)){ # sequence of angles
print(plot, vp=grid::viewport(angle=i)) # rotate with differen angles
ggplot2::ggsave(paste0("plots/plot_", i, ".png")) # save every plot with the name of the angle
}
警告是:警告:無法剪輯到旋轉的視口
如何正確剪輯視口?
uj5u.com熱心網友回復:
Ggsave 保存您在此函式上顯示的最后一個圖。在您的情況下,print被視為基本圖,因此將以相同的方式保存。
試試這個回圈:
for(i in seq(-90, 0, by = 30)){ # sequence of angles
png(paste0("plot_", i, ".png"), width = 500, height = 500) # open the file
pushViewport(viewport(name = "rotate", angle = i, clip = "off", width = 0.7, height = 0.7))
print(plot, vp="rotate") # rotate with differen angles
dev.off() # close the file
}
輸出:

轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/515271.html
標籤:rggplot2保存
上一篇:正確繪制geom_errorbar()以適應組的最小值/最大值
下一篇:計算中位數的缺失值問題
