[R-sig-Geo] putting scalebar and north arrow on google map

Tim Appelhans tim.appelhans at gmail.com
Mon Jul 18 14:36:02 CEST 2016


My suggestion would be the wonderful tmap package. It is, however, using 
OpenStreetMap rather than google for background maps AFAIK.

Tim

On 18.07.2016 14:32, Manuel Spínola wrote:
> Or you can try the package ggsn with the package ggmap
>
> Manuel
>
> 2016-07-17 22:57 GMT-06:00 Chris Lusk <clusk at waikato.ac.nz>:
>
>> Hi - I've made a map to show the spatial arrangement of my plots, and would
>> now like to add a scale bar (in hundreds of metres) and a north arrow. I've
>> seen several solutions online, most of which threw error messages when I
>> tried them. Although the solution below doesn't give an error message, it
>> doesn't actually add anything to the map!
>>
>> Any advice would be appreciated.
>>
>> Chris
>> ..........
>>
>> library(ggplot2)
>> library(ggmap)
>> library(maps)
>> library(GISTools)
>>
>> ##Coordinates of four types of plots
>> Gaps <- read.table(text="lon lat
>> 176.431823     -38.086894
>> 176.4329002     -38.08855667
>> 176.4286505     -38.08421246
>> 176.4239767     -38.08297953
>> 176.4306576     -38.09032491
>> 176.4181457     -38.08283416
>> 176.4325089     -38.09042394
>> 176.4243027     -38.08215021
>> 176.4220882     -38.08720573
>> 176.430974    -38.093108", header = TRUE, strip.white = TRUE)
>>
>> Understorey <- read.table(text="lon lat
>> 176.431523   -38.086965
>> 176.418408   -38.082935
>> 176.4244189     -38.08242069
>> 176.4287644     -38.08372266
>> 176.4240118     -38.0823004
>> 176.4333778     -38.08853369
>> 176.4217424     -38.0876122
>> 176.4309304     -38.09055117
>> 176.4324084     -38.0907023
>> 176.430821   -38.093687", header = TRUE, strip.white = TRUE)
>>
>> Treeferns <- read.table(text="lon lat
>> 176.432134      -38.086298
>> 176.4246547     -38.08226916
>> 176.4335132     -38.08801622
>> 176.4183628     -38.08260261
>> 176.429       -38.08413018
>> 176.4213997     -38.08710868
>> 176.4304333     -38.09064678
>> 176.4324081     -38.0909994
>> 176.4242689     -38.08264669
>> 176.429837      -38.093061", header = TRUE, strip.white = TRUE)
>>
>> Margins <- read.table(text="lon lat
>> 176.4225302     -38.08177849
>> 176.427018     -38.08879161
>> 176.4207786     -38.08356826
>> 176.4315118     -38.08251629
>> 176.426456     -38.08920441
>> 176.426010   -38.088253
>> 176.422526   -38.082794
>> 176.421399   -38.084780
>> 176.429339   -38.092742", header = TRUE, strip.white = TRUE)
>>
>> ## Get the map at right zoom level
>> OkatainaMap <- get_googlemap(center = c(lon = 176.425, lat = -38.0845),
>> maptype='hybrid', zoom=15)
>>
>> ## Plot the points on the map
>> ggmap(OkatainaMap) +
>>    geom_point(data=Gaps, aes(x=lon, y=lat), pch=15, colour="chartreuse1",
>> size=2.5, alpha=1) +
>>    geom_point(data=Understorey, aes(x=lon, y=lat), pch=21, colour="gray40",
>> bg="black", size=3, alpha=1) +
>>    geom_point(data=Treeferns, aes(x=lon, y=lat), pch=23, colour="gray40",
>> bg="blue", size=2.5, alpha=1) +
>>    geom_point(data=Margins, aes(x=lon, y=lat), pch=17, colour="orange",
>> size=2.5, alpha=1)
>>
>> ##Add scale and north arrow (NEITHER COMMAND WORKS FOR ME)
>>
>> map.scale(x=176.42,y=-38.092, ratio=FALSE, relwidth=0.2, col="white")
>> north.arrow(xb=176.435, yb=-38.079, len=0.02, lab="N", col="white")
>>
>> ...................
>>
>>
>> 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*
>> ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~
>>
>>          [[alternative HTML version deleted]]
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> R-sig-Geo at r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>
>

-- 
#####################################
Tim Appelhans
Department of Geography
Environmental Informatics
Philipps Universität Marburg
Deutschhausstraße 12
Raum 00A08
35032 Marburg (Paketpost: 35037 Marburg)
Germany

Tel +49 (0) 6421 28-25957

http://environmentalinformatics-marburg.de/



More information about the R-sig-Geo mailing list