0

I want to manually create a legend for a plot. The script to create the plot is as follows:

ggplot(afr.ks)+
geom_segment(aes(y = Chr, yend = Chr, x = 0, xend = long), data = d.chr) +
geom_segment(aes(y = Chr, yend = Chr, x = pos1, xend = pos2), lwd = 3,
           colour = "red3") + ylab("Chromosome")  + xlab("Position (bp)")+
geom_segment(aes(y = chr, yend = chr, x = cen.pos1, xend = cen.pos2),data=positions, lwd = 3,
           colour = "black")+scale_y_discrete( limits=c(1:22))+
geom_segment(aes(y = Chr, yend = Chr, x = pos1, xend = pos2),data=Af.KS.HHD.95, lwd = 3,
           colour = "springgreen3")+
geom_segment(aes(y = Chr, yend = Chr, x = pos1, xend = pos2),data=Af.KS.HHD.100, lwd = 3,
           colour = "springgreen4")

The plot this script creates: enter image description here

What I would like is a legend like the following figure (made in photoshop) enter image description here

This is not a duplicate question! I'm not getting anything when applied the solutions in different questions regarding this issue!

Cisco
  • 137
  • 7
  • I don’t think so. It’s not the same problem. I try to follow the guidelines in different questions regarding this topic and I could not get it. – Cisco Apr 10 '18 at 08:56
  • In my case Im not getting anything with scale_color_manual(). – Cisco Apr 10 '18 at 08:59
  • You need to move the color mappings **into** `aes()`, in order to get the desired result from `scale_color_manual()`. This looks like an exact duplicate. If you still think it's not, at least provide the datasets referenced in your code so that others can reproduce the problem. See [here](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – Z.Lin Apr 11 '18 at 02:10

0 Answers0