2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

ggplotで描画したグラフをまとめてpdfに保存する

Posted at

通常、画像ファイルを保存する場合、ggsave関数を活用する。これを用いて、ファイルの種類を指定すれば.png, .jpg, .pdfなど選択できる。
一方で、複数のファイルをまとめて保存した場合はほかの保存方法が便利。
例えば、以下の事例。pdf関数を活用し、dev.off()で締めくくると、その間に描画したものがすべて1つのpdfに保存される。

ggplot.R
library(ggplot2)

pdf("graphs.pdf") #ファイル名を指定
ggplot(data1, aes(x = X)) + geom_bar()
ggplot(hof_eras, aes(x = X, y = Y)) +  geom_point()
dev.off() #ここまで保存させる

また、余談だが
coord_flip()関数を使うと、描画したグラフのx軸、y軸を反対にする。

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?