FYI: I'm fairly new to ggplot2 and ggmap so I apologize for the sloppy code but it is the only way I've been able to plot sets of groups of points where each group has it's own color. Also my os is ubuntu.
I'm trying to add a legend, to a ggmap object and in particular a legend with a continuos gradient transitioning the colors. Any advice? I've tried the legend attribute in ggmap but it doesn't seem to be working. Below is what I have so far.
syd = get_map(location = center, zoom = zoom, maptype = type,color = "bw")
(SYDmap = ggmap(syd, extent = "panel",legend="right")+ annotate('point',x=lng[[1]],xend=max(lng[[1]]),y=lat[[1]],yend=max(lat[[1]]),colour=colorval[1],cex=cexval,pch=pchval))
for(i in 2:(topnum - 1))
SYDmap<- SYDmap + annotate('point',x=lng[[i]],xend=max(lng[[i]]),y=lat[[i]],yend=max(lat[[i]]),colour=colorval[i],cex=cexval,pch=pchval)
i=topnum; (SYDmap <- SYDmap + annotate('point',x=lng[[i]],xend=max(lng[[i]]),y=lat[[i]],yend=max(lat[[i]]),colour=colorval[i],cex=cexval,pch=pchval)) + guides(fill = "colourbar")
Instead of using
annotate
, here's a method that adds a point layer usinggeom_point
. Almost any geom can be added to a ggmap object as it would be added to a ggplot object. BecauseSize
(see the contents of thedf
data frame below) is a colour aesthetic in the call togeom_point
, the legend is generated automatically.