categorical-data - 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)
解决方案
我想过这个问题。答案在我的截图中。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)
推荐阅读
- flutter - 从 JSON 文件中获取数据时遇到范围错误
- apache-spark - 火花表操作 - 列值到行和行值转置
- android - 指定为非 null 的参数为 null - 在 Kotlin 中加载图像
- php - 如何检查是否是第一次在 foreach 迭代中的 if 语句中找到值
- python - 使用 ansible 和 python3 在 ubuntu 上安装 docker
- python - 在单个 Docker 容器中开发 ROS 节点?
- javascript - 如何使用 Leaflet 刷新或实时图像叠加
- r - 如何在R中做一个替换字段?
- python - 分配 n 行不同的值
- python - smtplib Python中的TLS和SSL有什么区别