我无法控制 ggplot 中条形图的颜色
require(mice)
require(ggplot2)
impute <- mice(nhanes, seed = 101)
ldt <-complete(impute,"long", include=TRUE)
ldt$Imputed<-ifelse(ldt$".imp"==0,"Observed","Imputed")
ggplot(ldt[!is.na(ldt$hyp),], aes(x= factor(hyp), colour=Imputed)) +
geom_bar() +
facet_wrap(~.imp, nrow = 1) +
scale_y_continuous(expand = c(0,0))
这使:
但是我希望条形图充满颜色,所以我尝试了:
ggplot(ldt[!is.na(ldt$hyp),], aes(x= factor(hyp))) +
geom_bar(colour = Imputed) +
facet_wrap(~.imp, nrow = 1) +
scale_y_continuous(expand = c(0,0))
但这给出了错误:
Error in do.call("layer", list(mapping = mapping, data = data, stat = stat, :
object 'Imputed' not found