简体   繁体   English

什么颜色列必须是分类的,而不是 R 中的数字意味着什么?

[英]What does color column must be categorical, not numeric mean in R?

library(ggplot2)

library(GGally)

ggpairs(diab, aes(color=diabetes, alpha=0.75), lower=list(continuous="smooth"))+ theme_bw()+

labs(title="Correlation Plot of Variance(diabetes)")+

theme(plot.title=element_text(face='bold',color='black',hjust=0.5,size=12))



Error in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm,  : 
  `mapping` color column must be categorical, not numeric

In order to assign colors, you must give categories to ggplot .为了分配颜色,您必须为ggplot指定类别。 A numerical vector can have infinite values, so the function doesn't know how to assign colors to it, thus you need a factor .数值向量可以具有无限值,因此该函数不知道如何为其分配颜色,因此您需要一个factor You can transform diabetes to a factor by doing:您可以通过以下方式将diabetes转化为一个因素:

diab$diabetes = as.factor(diab$diabetes)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM