11
12

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 5 years have passed since last update.

ggplot2で良く使うオプションをまとめて使いやすくしておく。

Posted at

ggplot2でよく使うオプションをlistでまとめておくことで、いつものオプションを簡単に呼び出す事が出来るTipsです。

以下のような記述を.RProfileにしておきます。

ggtemplate <- list(my_ggtheme(),scale_y_continuous(labels=comma))
ggline <- list(ggtemplate,geom_line(alpha=0.5))
ggpoint <- list(ggtemplate,geom_point(size=3),
                geom_point(size=1.5,colour="white",alpha=0.1))

※my_ggthemeは自作のggplot2のテーマです。

上記のように用意しておくことで、以下のように + でつなげて簡単にオプションを反映出来ます。

ggplot(diamonds,aes(x=carat,y=price,colour=color)) + ggpoint + ggline

長くなりがちなggplotのコードを短くすることが出来るのでお勧めです。

11
12
1

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
11
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?