Skip to content

Instantly share code, notes, and snippets.

@sachsmc
Last active May 29, 2018 21:36
Show Gist options
  • Save sachsmc/8e3863ebd20284a49e74 to your computer and use it in GitHub Desktop.
Save sachsmc/8e3863ebd20284a49e74 to your computer and use it in GitHub Desktop.
Add manual legend in ggplot2
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))
@yaolsen
Copy link

yaolsen commented May 29, 2018

Hi everyone,
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
capture

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment