本文へスキップ
からだにいいもの

Rのトピックスを中心に『まだ、まだ、知らない、役に立つ情報?』を発信します。

Rで解析:アカデミー賞の芸術に触れながら。カラーパレット「wesanderson」パッケージ

「からだにいいもの」でも資料の配色参考として、アニメキャラの目や髪の毛、画面などの色をカラーパレットとして紹介してきました。紹介するパッケージは映画監督「ウェス・アンダーソン」の作品から作られたカラーパレットが収録されています。

アンダーソン監督の作品は2014年に日本でも公開され、アカデミー賞も受賞した「グランド・ブダペスト・ホテル」などがあります。本パッケージを利用して、アカデミー賞の芸術に触れながら解析を楽しんでみてはいかがでしょうか。個性がありますが、大変魅力的な作品が多いオススメの監督です。

パッケージのバージョンは0.3.6。windows11のR version 4.2.2で確認しています。

パッケージのインストール

下記コマンドを実行してください。

#パッケージのインストール
install.packages("wesanderson")
スポンサーリンク

実行コマンドの紹介

詳細はコマンド、パッケージヘルプを確認してください。

[code language="R"]
#パッケージの読み込み
library("wesanderson")

#収録内容一覧をプロット
#wes_palettesの収録内容を取得
ItemVol <- length(wes_palettes)
###データのプロット#####
#軸の設定
xRange <- seq(0, 2, by = 2/ItemVol)

#グラフ幅の設定
xWidth <- seq(2/ItemVol, 2, by = 2/ItemVol)

#プロット領域の作成
par(bg = wes_palettes[[2]][3])
plot(0:2, 0:2, type = "n", axes = FALSE,
     xlab = "", ylab = "", main = "wes_palettes")
box()

for(k in seq(ItemVol)){

  #データのプロット
  rasterImage(as.raster(wes_palettes[[k]]), 
              xRange[k], 0.7, xWidth[k], 2, interpolate = FALSE)
  text(xRange[k], 0.3, names(wes_palettes[k]), cex = 0.8,
       srt = 90, adj = c(0.5, 2.5), col = wes_palettes[[1]][2])

}

#使い方例
library("ggplot2")
qplot(x = factor(cyl), data = mtcars, geom = "bar", fill = factor(vs)) + 
  scale_fill_manual(values = wes_palette("Royal1"))

出力例

・収録内容一覧をプロット
 パレット名とともに表示しています。クリックで拡大表示されます。

wesanderson1

・使い方例

wesanderson2

少しでも、あなたのウェブや実験の解析が充実しますように!!

このコードの続きをAIに聞く

スポンサーリンク
Prices and shipping availability may change. Please refer to the product page at time of purchase.
Content displayed on this site is provided by Amazon and may be updated or removed.
Amazon Associate, karada-good earns income through qualifying sales.