i using ggmap produce map of europe, on top of plotting several points in colors. add legend. far, code plotting looks this:
map <- get_map(location = "europe", zoom = 3, color = "bw") p <- ggmap(map) p <- p + geom_point(data=d, aes(x=lon, y=lat),size=1.25, col="gray40") p <- p + geom_point(data=d.stations1, aes(x=lon, y=lat),size=1.5, col=colors[1]) p <- p + geom_point(data=d.stations2, aes(x=lon, y=lat),size=1.5, col=colors[2]) p <- p + geom_point(data=d.stations3, aes(x=lon, y=lat),size=1.5, col=colors[3]) p <- p + geom_point(data=d.reference.station, aes(x=lon, y=lat),size=1.5, col=color.ref) p <- p + scale_x_continuous(limits = c(-25,62), expand = c(0, 0)) + scale_y_continuous(limits = c(27,75), expand = c(0, 0)) + xlab("longitude") + ylab("latitude") ggplot_build(p)` the objects d.stations1, d.stations2 , d.stations3 subsets of rows of d, with
d <- data.frame(st = stations.list, lat = latitudes, lon = longitudes) essentially, plot points in gray, , plot subsets on top of in chosen colors.
now, have legend next plots (preferably not on map), colors explained points.
some of plotted points in d.stations1 belong d.stations2 , on, not sure how can produce working legend. have tried
i have tried adding
p <- p + scale_color_manual(name = "distance", labels = c(1:3), values = colors) + theme(legend.position = "bottom") but gives error (scale colour defined)
Comments
Post a Comment