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'?
This article describes how to remove legend from a plot created using the ggplot2 package. Hide the entire legend to create a ggplot with no legend. Remove the legend for a specific aesthetic. Load required packages and set the theme function theme_minimal () as the default theme: Create a box plot using the ToothGrowth data set.
After the plot creation, it’s possible to remove the legend as follow: p + theme (legend.position = "none") Remove legend for a particular aesthetic Create a scatter plot with multiple aesthetics (guides)
Create a box plot using the ToothGrowth data set. During the plot creation, you can decide to turn off legends by using the argument show.legend = FALSE. For example: This section contains best data science and self-development resources to help you on your path.
Our example data contains four columns, the first column contains the x-values; the second column contains the y-values; the third column contains the colors for the dots of our plot; and the fourth column contains the filling color for a regression line that we will draw to our graphic. So let’s see how this data looks in ggplot2 by default.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With