Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

overlapping shape and character in ggplot legend

Tags:

r

ggplot2

When I plot points and text with the same colour, the a and the shape overlap in the legend.

Can I tell ggplot not to draw the a in the legend? How?

M <- data.frame(t=letters[1:16],
            xx=runif(16),
            yy=runif(16),
            g=rep(c("A","B","C","D"),4))
str(M)

ggplot(M,aes(x=xx,y=yy,label=t,colour=g)) + 
       geom_point(shape=3) + 
       geom_text(vjust=0,hjust=0) + 
       scale_colour_discrete()

like image 783
scoa Avatar asked Oct 19 '22 13:10

scoa


1 Answers

Just add show_guide = F for your geom_text:

ggplot(M,aes(x=xx,y=yy,label=t,colour=g)) + 
  geom_point(shape=3) + 
  geom_text(vjust=0,hjust=0, show_guide = F) +
  scale_colour_discrete()

enter image description here

like image 86
mucio Avatar answered Oct 22 '22 22:10

mucio