当我使用以下代码生成密度图时:
require(ggplot2)
set.seed(seed=10)
n <- 10000
s.data <- data.frame(score = rnorm(n,500,100),
gender = sample(c("Male","Female","No Response"),size=n,replace=T,prob=c(.4,.55,.05)),
major = sample(c("A","B","C","D"),size=n,replace=T,prob=c(.02,.25,.05,.68)))
ggplot(s.data, aes(major,..density..,fill=major,group=1)) +
geom_histogram() + facet_wrap(~ gender)
我无法通过颜色区分“主要”类别。
我想要得到的是在颜色和图例的意义上类似于这个频率图的密度图:
ggplot(s.data, aes(major,fill=major)) +
geom_histogram() + facet_wrap(~ gender)