I'm working on some density plots where the fill is conditional on a value (0.05)
library(plyr)
library(ggplot2)
allNorm<-data.frame(value=rnorm(300),
aCategory=rep(1:3, c(100, 100, 100)))
allNorm<-ddply(allNorm, .(aCategory), mutate,
shapWilkP=shapiro.test(value)$p.value)
mixed<-data.frame(value=c(rlnorm(200), rnorm(100)),
aCategory=rep(1:3, c(100, 100, 100)))
mixed<-ddply(mixed, .(aCategory), mutate,
shapWilkP=shapiro.test(value)$p.value)
ggplot(allNorm, (aes(x=value)))+
geom_density(aes(fill=shapWilkP>0.05))+
facet_wrap(~aCategory)
ggplot(mixed, (aes(x=value)))+
geom_density(aes(fill=shapWilkP>0.05))+
facet_wrap(~aCategory)
This works (almost) - I just need to work out how to force TRUE to be blue all the time.
Could anybody help?
Thanks
添加到两个绘图scale_fill_manual()
,您可以在其中为TRUE
和FALSE
值设置所需的颜色。
+ scale_fill_manual(values=c("FALSE"="red","TRUE"="blue"))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.