-2

Probably very basic question about the legends in ggplot2 (sorry i am basic user user of R), I use this:

p<-ggplot(bAfr_topS1, aes(MAF, V3))+ geom_point()
p <- p+  geom_point(data=bEur_topS1,aes(MAF,V3),colour="red")+
  geom_point(data = bSas_topS1, aes(MAF, V3), colour="blue")

print(p)

but can't see the legends in output plot, any suggestion please? what should i add in?

bha
  • 77
  • 2
  • 7
  • 1
    You're using `ggplot2` the *wrong* (not optimal) way. Please check online tutorials (you need to bind your data and set color in `aes`). – pogibas Jul 10 '18 at 09:52
  • Please share a reproducible example. Or use dput, so that others can understand your data and problem. – rar Jul 10 '18 at 09:56

1 Answers1

0

It's difficult to give specific help without any data, but to illustrate the point @PoGibas is making and to get you started, try the following

library(tidyverse)
bind_rows(list(AF = bAfr_topS1, EU = bEur_topS1, PK = bSas_topS1), .id = "src") %>%
    ggplot(aes(MAF, V3, colour = as.factor(src))) +
    geom_point()

This assumes that bAfr_topS1, bEur_topS1, bSas_topS1 all have the same column structure.

Maurits Evers
  • 49,617
  • 4
  • 47
  • 68