1

I used the picture's numbers as data points in this scatterplot, which was created with ggplot2. As a result, the legend key is an 'a'. Instead, I would need ordinary dots (also colored by clusters) beside the labels. How can I realize that? I used the following code:

ggplot(data, aes(x=vx, y=vy, color=Cluster, shape=Cluster)) + geom_text(aes(label=PicNr),
  size =6, fontface = "bold",
  check_overlap = T,
  show.legend=T) +
  theme_bw(base_size = 20)+
  theme(legend.position="top") 

Thanks for your help!

legend

Mikko Marttila
  • 10,972
  • 18
  • 31
kairos
  • 43
  • 4

1 Answers1

1

For this you can do something like

library(ggplot2)

ggplot(mtcars, aes(mpg, wt))+
  geom_text(aes(label = cyl, color = factor(cyl)), show.legend = FALSE)+
  geom_point(aes(color = factor(cyl)), alpha = 0)+
  guides(color = guide_legend(override.aes = list(alpha = 1, size = 4)))

so your code would read something like:

ggplot(data, aes(x=vx, y=vy, shape=Cluster)) + 
  geom_text(aes(label=PicNr, color=Cluster), size =6, fontface = "bold", check_overlap = T, show.legend=F) +
  geom_point(aes(color=Cluster), alpha = 0)+
  theme_bw(base_size = 20)+
  theme(legend.position="top")+
  guides(color = guide_legend(override.aes = list(alpha = 1, size = 4)))

Created on 2018-08-18 by the reprex package (v0.2.0).

AndS.
  • 7,748
  • 2
  • 12
  • 17
  • Thanks a lot for your support! I appreciate that. I added shape #19 in guides - now also all legend keys have the same shape: guides(color = guide_legend(override.aes = list(alpha = 1, size = 4, shape = 19))) – kairos Aug 18 '18 at 19:12