简体   繁体   中英

Suppress the legend in a ggplot2/qplot density plot

I've looked through the description and the book on ggplot2 and cannot find a simple way of eliminating the legend in a simple density plot with a filled color.

Here is what I've tried with a simple sequence of 1000 numbers (plotseries) that had about 200 NA in the first 200 spots.

qplot(plotseries,geom="density",fill="red",na.rm=TRUE,show_guide=FALSE)

qplot(plotseries,geom="density",fill="red",na.rm=TRUE,legend.position="none")

I looked at the online ggplot2 doc and could not find anything there either....

And what would the ggplot equivalent be? fill=I("red") doesn't seem to be accepted in the following

ggplot(SPXweekly,aes(x=SPX, fill=I("royalblue3"))) + geom_density(alpha=0.75)

SPXweekly is a data.frame with columns named Date and SPX.

If you just use the normal qplot command and then add + theme(legend.position = "none") to your code, it will remove the legend. So, your code will look as follows:

qplot(plotseries,geom="density",fill="red",na.rm=TRUE) + theme(legend.position="none")

Usually such things work just as they would work in the ggplot2 command.

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