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

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

Analysis in R: Different Colors, Different Colors, Different Colors! The “randomcoloR” package

Color not only affects the quality of materials, but is also profound, expressing feelings such as liking, disliking, and melancholy. We would like to introduce a package that allows you to create such “colors” randomly.

The following is an introduction to the “scales” package used in the “Execute command”. This package is recommended for expressing colors.

・Analysis in R: “sales” package
 https://www.karada-good.net/analyticsr/r-109/

Package version is 1.1.01. R version 4.2.2 is confirmed.

Install Package

Run the following command.

#Install Package
install.packages("randomcoloR")
スポンサーリンク

Execute command

See the command and package help for details.

#Loading the library
library("randomcoloR")

#Needed to plot colors
#Install the scales package if not already present
if(!require("scales", quietly = TRUE)){
  install.packages("scales");require("scales")
}

#Getting a random color: distinctColorPalette command
#See also:http://tools.medialab.sciences-po.fr/iwanthue/theory.php
#Set the number of acquisitions:k option
CleateCol <- distinctColorPalette(k = 81)
#plot
show_col(CleateCol, labels = FALSE, borders = "#a87963")

#Random color acquisition:randomColor command
#Number of colors to create:count option
#Specify the hue of the color:hue option;"random","red","orange","yellow",
#"green","blue","purple","pink","monochrome"
#Specify the luminosity of the color:luminosity option;"random","light","bright","dark"
RandomCol <- randomColor(count = 6, hue = "blue", luminosity = "light")
#check
RandomCol
[1] "#80abed" "#a9e7fc" "#84e9f4" "#78d3ed" "#8a8aea" "#96ddea"
#plot
show_col(RandomCol, labels = TRUE, borders = "#a87963")

Output Examples

・distinctColorPalette command

distinctColorPalette

・randomColor command

randomColor

I hope this makes your analysis a little easier !!

スポンサーリンク
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.