Question

I have a quite simple question I suppose. If I draw a scatter plot like this:

 data <- data.frame(lon=runif(100)*3+10, lat=runif(100)*5+42, value=rnorm(100)*100)
 ggplot() + geom_point(aes(x=lon, y=lat,  color=value), data=data)

the legend is properly displayed and the breaks are specified.

propper legend

but when i use a map as background:

 SHmap <- qmap(c(lon=mean(data[,'lon'], na.rm=TRUE), lat=mean(data$lat, na.rm=TRUE)), zoom=7)
 SHmap <- SHmap + geom_point(aes(x=lon, y=lat,  color=value), data=data)
 SHmap

no breaks specified here

am I doing something wrong or is this behaviour intended?

Was it helpful?

Solution

Try adding extent="panel" to your qmap call. The default, extent="device", puts a theme_nothing onto the plot which gets rid of the scales labels.

SHmap <- qmap(c(lon=mean(data[,'lon'], na.rm=TRUE), lat=mean(data$lat, na.rm=TRUE)), 
              zoom=7, extent="panel")
SHmap <- SHmap + geom_point(aes(x=lon, y=lat,  color=value), data=data)
SHmap

enter image description here

Or just override those parts of the theme which control the legend so that they show up.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top