ggplotでfigureを横並びにする
eggパッケージを使う
code:R
library("egg")
# fig1a = ggplot()
# fig1b = ggplot()
fig1 = ggarrange(fig1a, fig1b, nrow=1)
ggsave(plot=fig1, "figure/figure1.pdf", width = 20, height = 14, device=cairo_pdf)
応用例
リストにfigureをまとめて格納する
code:R
figs = list()
fig_count = 1
for (item in items) {
fig = ggplot(data) +
geom_line(aes(x = x, y = y))
figsfig_count = fig
fig_count = fig_count + 1
}
fig_merged = do.call(ggarrange, c(figs, nrow=4))
fig_merged = do.call(ggarrange, c(figs, ncol=4))
do.callは以下と同じ
code:R
ggarrange(
figs1,
figs2,
figs3,
figs4,
nrow=4
)
code:R
ggsave(plot=fig_merged, "figure1.pdf", width = 20, height = 14, device=cairo_pdf)
ggplot R figure
public