简体   繁体   中英

Removing 'dot' element from ggplot2 legend

Example Code:

EmigProb<-c(rep(seq(0.1,0.8,length=5),4),rep(seq(0.1,0.8,length=5),4))
RemainEmigProb<-c(rep(0.2,5),rep(0.4,5),rep(0.6,5),rep(0.8,5),rep(0.2,5),rep(0.4,5),rep(0.6,5),rep(0.8,5))
Value<-rnorm(40,5,3)
Parameter<-c(rep("Survival",20),rep("Resight",20))
fakedata<-data.frame(EmigProb=EmigProb,RemainEmigProb=RemainEmigProb,Value=Value,Parameter=Parameter)


q <-ggplot(fakedata,aes(EmigProb,Value,shape=factor(RemainEmigProb),colour=factor(Parameter),linetype=factor(RemainEmigProb)))+scale_colour_discrete("Parameter")+scale_linetype_discrete("Remain Emigrant Probability")+scale_shape_manual("Remain Emigrant Probability",values=c(0,5,6,15))
q <- q + layer(geom="point")
q <- q + layer(geom="line")
q

示例图

In this example, is there any way to remove the 'dots' from the 'Parameter' legend for 'Resight' and 'Survival'?

Add this to your plotting command:

guides(colour = guide_legend(override.aes = list(shape = NA)))

Details on customizing legends along with lots more wonderful ggplot2 0.9 wisdom can be found here: http://cloud.github.com/downloads/hadley/ggplot2/guide-col.pdf

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM