16
17

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のデフォルトの色を知りたい

Last updated at Posted at 2015-07-29

Q.

ggplot2のデフォルトの色を知りたいです。RGBも知りたいです。

A.

以下のコードで知ることができます。

色分けの基準がfactorの場合

OK_example1.R
ggColorHue <- function(n, l=65) {
  hues <- seq(15, 375, length=n+1)
  hcl(h=hues, l=l, c=100)[1:n]
}

cols       <- ggColorHue(n=4)
cols_dark  <- ggColorHue(n=4, l=45)
cols_light <- ggColorHue(n=4, l=85)

col2rgb(cols)
scales::show_col(cols)

col2rgbはrgbを計算するのに使っています。最後の行の結果は以下の通りです。
OK1.png

色分けの基準が連続値の場合

OK_example2.R
cols <- colorRampPalette(c("#132B43", "#56B1F7"))(n=25)
col2rgb(cols)
scales::show_col(cols)

n=25はテキトーです。

OK2.png

参考資料

http://stackoverflow.com/questions/8197559/emulate-ggplot2-default-color-palette
http://docs.ggplot2.org/current/scale_gradient.html

16
17
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
16
17

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?