[R-sig-Geo] how to label points on a google map?

Kent Johnson kent3737 at gmail.com
Sun Jul 3 18:20:28 CEST 2016


On Sun, Jul 3, 2016 at 6:00 AM, <r-sig-geo-request at r-project.org> wrote:
>
> Subject: [R-sig-Geo] how to label points on a google map?
> Message-ID:
>         <CABqyKtsmU6xCHqQJm1v=Fx=
> 2GDDeg0bscMPWL5im3L+EYnpwUA at mail.gmail.com>
> Content-Type: text/plain; charset="UTF-8"
>
> Hi - I'd appreciate any suggestions as to how I can superimpose numbers
> over the coloured symbols I've plotted on a google map using the code
> below. The numbers I want to use as labels are in the 1st column of the
> table. I've seen a couple of solutions online, but neither has worked for
> me.
> ..........
>
> library(ggplot2)
> library(ggmap)
>
> Rangitikei <- read.table(text="number lon lat
> 11  175.74 -39.55
> 10  175.72 -39.65
> 9  175.97 -39.7
> 8  175.78 -39.81
> 7  175.67 -39.84
> 6  175.894 -39.84
> 5  175.96 -39.85
> 4  175.60 -39.90
> 3  175.37 -39.905
> 2  175.53 -39.96
> 1  175.60 -39.99", header = TRUE, strip.white = TRUE)
>
> # Get the map
> RangitikeiMap <- get_googlemap(center = c(lon = 175.736, lat = -39.8),
> maptype='roadmap', zoom=10)
>
> # Plot the points on the map
> ggmap(RangitikeiMap) +
>   geom_point(data=Rangitikei, aes(x=lon, y=lat), colour="gold2", size=6,
> alpha=.7)
>
>
Add
 + geom_text(data=Rangitikei, aes(x=lon, y=lat, label=number))
to the code above.

Kent

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list