【发布时间】:2021-11-28 20:39:07
【问题描述】:
我正在尝试绘制以下数据:
library(ggplot2)
my_data <- data.frame( a = abs(rnorm(1000,17,10)),
b = a)
my_data$col = as.factor(ifelse(my_data$a > 17, "red", "blue"))
ggplot(my_data, aes(x=a)) +
geom_histogram(binwidth=1)
但由于某种原因,当我尝试添加颜色时,出现以下错误:
ggplot(my_data, aes(x=a)) +
geom_histogram(binwidth=1, color = my_data$col)
Error: Aesthetics must be either length 1 or the same as the data (59): colour
谁能告诉我如何解决这个错误?
谢谢
【问题讨论】:
标签: r ggplot2 data-visualization