わらってごまかす

ごまかしちゃだめ

Rで目にやさしい色を使う

rでプロットするとき、col="red"とかcol="blue"とかやるが、なんとも目に痛い色で嫌だ。

お気に入りの自分用パレットをつくろうかと思ったが、RColorBrewerパッケージが解決してくれた。

library(RColorBrewer)
cols <- brewer.pal(8,"Set1") # 引数1:何色使うか 引数2:パレットの名前

あとは色を指定するとき、cols[1]やcols[8]とするだけで、8色の目にやさしい色が使える。ちなみに.Rprofileに書いておくと便利。

例えばこんな感じで使う

plot(iris$Sepal.Length,iris$Sepal.Width,pch=16,col="red")
plot(iris$Sepal.Length,iris$Sepal.Width,pch=16,col=cols[1])
plot(iris$Sepal.Length,iris$Sepal.Width,pch=16,col="blue")
plot(iris$Sepal.Length,iris$Sepal.Width,pch=16,col=cols[2])
plot(iris$Sepal.Length,iris$Sepal.Width,pch=16,col="green")
plot(iris$Sepal.Length,iris$Sepal.Width,pch=16,col=cols[3])

f:id:fujit33:20150412210611p:plain:w300f:id:fujit33:20150412210618p:plain:w300
f:id:fujit33:20150412210612p:plain:w300f:id:fujit33:20150412210615p:plain:w300
f:id:fujit33:20150412210614p:plain:w300f:id:fujit33:20150412210616p:plain:w300

使えるカラーパレット一覧と名前はdisplay.brewer.all()で見られる。

display.brewer.all()

f:id:fujit33:20150412211331p:plain
けっこうお気に入り。
(参考:RColorBrewer | Rのカラーパレットの使い方