Rで解析:いろいろな色が、イロイロあります!「randomcoloR」パッケージ

色は資料の出来を左右するだけでなく、好き・嫌い・憂鬱などの気持ちを表現するなど奥が深いものです。そんな「色」をランダムに作成できるパッケージの紹介です。

実行コマンドで利用している「scales」パッケージの紹介は下記です。色を表現するのにオススメなパッケージです。

・Rで解析:「scales」パッケージ
 https://www.karada-good.net/analyticsr/r-109/

パッケージバージョンは1.1.0.1。実行コマンドはR version 4.2.2で確認しています。

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

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

#パッケージのインストール
install.packages("randomcoloR")

実行コマンド

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

#パッケージの読み込み
library("randomcoloR")

#色をプロットするのに必要
#scalesパッケージがなければインストール
if(!require("scales", quietly = TRUE)){
  install.packages("scales");require("scales")
}

#ランダムにカラーを取得:distinctColorPaletteコマンド
#参照:http://tools.medialab.sciences-po.fr/iwanthue/theory.php
#取得数を設定:kオプション
CleateCol <- distinctColorPalette(k = 81)
#&#12503;&#12525;&#12483;&#12488;
show_col(CleateCol, labels = FALSE, borders = "#a87963")

#&#12521;&#12531;&#12480;&#12512;&#12395;&#33394;&#12434;&#21462;&#24471;:randomColor&#12467;&#12510;&#12531;&#12489;
#&#20316;&#25104;&#12377;&#12427;&#33394;&#25968;:count&#12458;&#12503;&#12471;&#12519;&#12531;
#&#33394;&#12398;&#33394;&#30456;&#12434;&#25351;&#23450;:hue&#12458;&#12503;&#12471;&#12519;&#12531;;"random","red","orange","yellow",
#"green","blue","purple","pink","monochrome"&#12364;&#35373;&#23450;&#21487;&#33021;
#&#26126;&#24230;&#12434;&#25351;&#23450;:luminosity&#12458;&#12503;&#12471;&#12519;&#12531;;"random","light","bright","dark"&#12364;&#35373;&#23450;&#21487;&#33021;
RandomCol <- randomColor(count = 6, hue = "blue", luminosity = "light")
#&#30906;&#35469;
RandomCol
[1] "#80abed" "#a9e7fc" "#84e9f4" "#78d3ed" "#8a8aea" "#96ddea"
#&#12503;&#12525;&#12483;&#12488;
show_col(RandomCol, labels = TRUE, borders = "#a87963")

出力例

・distinctColorPaletteコマンド

distinctColorPalette

・randomColorコマンド

randomColor

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

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, This site earns income through qualifying sales.
タイトルとURLをコピーしました