Last active
May 29, 2018 21:36
-
-
Save sachsmc/8e3863ebd20284a49e74 to your computer and use it in GitHub Desktop.
Add manual legend in ggplot2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tm <- data.frame(Marker = sort(rep(letters[1:5], 10)), x = runif(50), y = runif(50)) | |
p1 + geom_line(data = tm, aes(linetype = Marker, x = x, y = y), alpha = 0) + | |
scale_linetype(guide = guide_legend(override.aes = list(alpha = 1)), labels = | |
c(expression(A[1]), expression(A[2]), expression(A[3]), expression(A[4]), expression(A[5]))) + | |
theme(legend.position = c(.75, .25)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi everyone,
![capture](https://user-images.githubusercontent.com/39747154/40686877-58f8764e-6388-11e8-8a3f-e346040e349d.GIF)
I created a Midwest map and wanted to add a little right triangles representing clinics to the map by the code below
Midwest + geom_point(data=clinics, aes(x=lon, y=lat, group=group), size = 2, show.legend = F)
I wanted to manually create a legend to show that a little red triangle representing clinics.
Tried to reconstruct the data by adding variables like shape = 24 to the 'clinics' dataset and run the code like this
Midwest + geom_point(data=clinics, aes(x=lon, y=lat, group=group, shape=shape), size = 2, show.legend = T)
but get an error message saying 'Error: Continuous value supplied to discrete scale '
Any help will be appreciated! thanks, Ava