首页 > 解决方案 > Add Color to classes in scatterplot matrix (pairs)

问题描述

I have my class defined in "unscaled.BL_yFYield_CSUSHPINSA" (basically, 1:up 0:down). I wish to color the scatterplot into classes akin to how this example demonstrates species are supposedly highlighted by 3 colors (note, I've reduced my example to two colors).

http://www.sthda.com/english/wiki/scatter-plot-matrices-r-base-graphs

this image specifically is what I'm trying to achieve (coloring based on my_cols and a categorical variable). In the iris example, I only saw two species (when I iterated iris$species), but the online code uses 3 colors in the graph, so I'm not sure how that works data.

My example I have two colors for two classes (however, eventually I wish to extend my number of classes beyond 2).

Example, assuming BL_yFYield_CSUSHPINSA had the following values for categorical 0, 1, 2 and I had 3 colors defined in my_cols.

Right now when I graph the output, this is what I get

pre_MyData <- read.csv(file="https://raw.githubusercontent.com/thistleknot/FredAPIR/master/reduced.csv", header=TRUE, sep=",")

MyData <- pre_MyData[,11:18]

my_cols <- c("#00AFBB", "#E7B800") 
pairs(MyData[,1:8], pch = 19, cex = 0.5,
      col = my_cols[MyData$unscaled.BL_yFYield_CSUSHPINSA],
      lower.panel = NULL)

标签: categorical-data

解决方案


我想过这个问题。答案在我的截图中。my_cols 正在跳过 BL_yfield 中为 0 的值...(将其视为 null)。我可以尝试在传真后修复它,或者我可以在我的原始数据集中添加 1 以删除 0...

问题解决了

pre_MyData <- read.csv(file="https://raw.githubusercontent.com/thistleknot/FredAPIR/master/reduced.csv", header=TRUE, sep=",")

MyData <- pre_MyData[,11:18]

my_cols <- c("#00AFBB", "#E7B800") 
pairs(MyData[,1:8], pch = 19, cex = 0.5,
      col = my_cols[MyData$unscaled.BL_yFYield_CSUSHPINSA+1],
      lower.panel = NULL)

推荐阅读