Analysis in R: Presents an example of obtaining color data from a plot

RAnalytics
スポンサーリンク

Here is a simple example of how to get a color code from a plot. The packages used are “grid” and “KaradaColor”. The key is the “grid” package.

Each package is up to date at the time of introduction, and execution commands are verified with R version 4.2.3.

スポンサーリンク

Example

See the command and package help for details.

#Install the grid package if it is not already present
if(!require("grid", quietly = TRUE)){
  install.packages("grid");require("grid")
}
#Install the KaradaColor package if it is not already present
if(!require("KaradaColor", quietly = TRUE)){
  install.packages("KaradaColor");require("grid")
}

#Create triad color with specified color:KaradaColor::kg_create_tc command
#Create data to be retrieved from clicked coordinates
img <- kg_create_tc(basecols = "green")

#Plot: grid::grid.newpage, grid::grid.raster command
grid.newpage()
grid.raster(as.matrix(t(img)), width = 1,
            height = unit(0.5, "npc"), interpolate = F)

#Capturing click data: grid::grid.locator command
GetValue <- grid.locator("npc")

#Get color code from data
col_code <- img[trunc(GetValue$x * nrow(img) + unit(1, "npc")), 1]

#Display color codes on console: KaradaColor::kg_show_console command
kg_show_console(col_code)

Output Example


I hope this makes your analysis a little easier !!

Amazon audibleの登録の紹介

プライム会員限定で2024年7月22日まで3か月無料体験キャンペーン開催中です。無料体験後は月額1,500円で聞き放題です。なお、聞き放題対象外の本はAudible会員であれば非会員価格の30%引きで購入することが可能です。

Amazon audibleはプロのナレーターが朗読した本をアプリで聞くことができるサービスで、オフライン再生も可能です。通勤や作業のお供にAmazon audibleのご登録はいかがでしょうか。

・AmazonのAudible

https://amzn.to/3L4FI5o

Copied title and URL