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

Tony Gray tony.gray at utoronto.ca
Sun Jul 3 17:34:19 CEST 2016


Hi Chris...

I am no R guru, but I create maps like yours frequently. 

Using geom_text works for me. Like this:

-------------------------------------

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) +
    geom_text(data = Rangitikei, aes(x = lon, y = lat, label = number), size = 4)

-------------------------------------

Hope this works for you. 

-- Tony


---------------------
Anthony Gray, PhD
Director, Strategic Research
Office of the President
Office: +1 416 978 8792 / Mobile: +1 647 291 4894  
University of Toronto
Simcoe Hall, 27 King's College Circle, Room 206
Toronto ON M5S 1A1 Canada




Date: Sun, 3 Jul 2016 18:56:43 +1200
> 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)
> .........
> 
> 
> Dr. Chris Lusk
> Senior Research Fellow
> Environmental Research Institute
> The University of Waikato
> Private Bag 3105, Hamilton
> New Zealand / Aotearoa
> http://sci.waikato.ac.nz/sites/clusk/
> Ph 64 7 838 4205
> Senior Editor, *NZ J Botany*
> ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~








More information about the R-sig-Geo mailing list