0
由于时间过程,我有更多的图例项目,但我只想显示两个标签:Healthy和Patient。GGplot2更改图例项目
## Construct the data
healthy <- rnorm(100,mean=0,sd=1)
patientTimeA <- rnorm(100,mean=1,sd=1)
patientTimeB <- rnorm(100,mean=3,sd=1)
patientTimeC <- rnorm(100,mean=4,sd=1)
groupArray <- c(rep("H",100),rep("P",300))
timeArray <- c(rep(0,100),rep(10,100),rep(20,100),rep(30,100))
dataTab <- data.frame(group=groupArray,time=timeArray,value=c(healthy,patientTimeA,patientTimeB,patientTimeC))
dataTab$group <- paste(dataTab$group,dataTab$time,sep="_")
colVector <- c("red","blue","blue","blue")
p <- ggplot(dataTab,aes(x=group,y=value,fill=group)) +
geom_boxplot(alpha=0.7)+
scale_fill_manual(values=colVector)
print(p)