Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing 'dot' element from ggplot2 legend

Tags:

r

ggplot2

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

Example Graph

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

like image 677
user1399311 Avatar asked Jul 10 '12 16:07

user1399311


People also ask

How do I remove the legend from a ggplot2 plot?

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.

How to remove the legend from a scatter plot?

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)

How do I turn off Legends in a box plot?

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.

How does the data look in ggplot2?

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.


1 Answers

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

like image 66
bdemarest Avatar answered Oct 26 '22 20:10

bdemarest