私はggplot2
を使用して複数のプロットをプロットしようとしており、grid.arrange()
を使用してそれらを配置しています。ファイルにgrid.arrange()プロットを保存する
私はgrid.arrange()
後ggsave()
を使用する場合、すなわち
grid.arrange(sgcir1,sgcir2,sgcir3,ncol=2,nrow=2) ggsave("sgcirNIR.jpg")
を私は、グリッドのプロットを保存しない:私は私が持っている正確な問題を説明する誰かが、私はlinkから問題の説明から引用している見つけることができたので 最後の個々のggplot。 で表示されるプロットを実際に保存する方法はありますか ggsave()
またはこれと類似したものを使用していますか?古い方法
jpeg("sgcirNIR.jpg") grid.arrange(sgcir1,sgcir2,sgcir3,ncol=2,nrow=2) dev.off()
同じリンクを使用するよりも他の は、以下のソリューション提供します:しかし
require(grid)
require(gridExtra)
p <- arrangeGrob(qplot(1,1), textGrob("test"))
grid.draw(p) # interactive device
ggsave("saving.pdf", p) # need to specify what to save explicitly
を、私は中grid.arrange()
コールの出力を保存するためにggsave()
を使用する方法を見つけ出すことはできませんlinkから取得され、次のコード、:
library(ggplot2)
library(gridExtra)
dsamp <- diamonds[sample(nrow(diamonds), 1000), ]
p1 <- qplot(carat, price, data=dsamp, colour=clarity)
p2 <- qplot(carat, price, data=dsamp, colour=clarity, geom="path")
g_legend<-function(a.gplot){
tmp <- ggplot_gtable(ggplot_build(a.gplot))
leg <- which(sapply(tmp$grobs, function(x) x$name) == "guide-box")
legend <- tmp$grobs[[leg]]
return(legend)}
legend <- g_legend(p1)
lwidth <- sum(legend$width)
## using grid.arrange for convenience
## could also manually push viewports
grid.arrange(arrangeGrob(p1 + theme(legend.position="none"),
p2 + theme(legend.position="none"),
main ="this is a title",
left = "This is my global Y-axis title"), legend,
widths=unit.c(unit(1, "npc") - lwidth, lwidth), nrow=1)
# What code to put here to save output of grid.arrange()?
'png();を使用してください。 grid.arrange(); ggplot(); ggplot(); dev.off() ' – Andrie
' print(ggplot()) 'はありません? –
@DWinはい、おそらく!:-) – Andrie