This repository has been archived by the owner on Apr 12, 2021. It is now read-only.
forked from MarieAugerMethe/GISwithRDemo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MapsWithR.r
73 lines (50 loc) · 2.03 KB
/
MapsWithR.r
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
### Basic packages ###
library(sp) # classes for spatial data
library(raster) # grids, rasters
library(rasterVis) # raster visualisation
library(maptools)
# and their dependencies
###########################################################
### VISUALISATION OF GEOGRAPHICAL DATA ###
### RWORLDMAP ###
library(rworldmap) # visualising (global) spatial data
# examples:
newmap <- getMap(resolution="medium", projection="none")
plot(newmap)
mapCountryData()
mapCountryData(mapRegion="europe")
mapGriddedData()
mapGriddedData(mapRegion="europe")
### GOOGLEVIS ###
library(googleVis)
# visualise data in a web browser using Google Visualisation API
# demo(googleVis) # run this demo to see all the possibilities
# Example: plot country-level data
data(Exports)
View(Exports)
Geo <- gvisGeoMap(Exports, locationvar="Country", numvar="Profit",
options=list(height=400, dataMode='regions'))
plot(Geo)
print(Geo)
# this HTML code can be embedded in a web page (and be dynamically updated!)
# Example: Plotting point data onto a google map (internet)
data(Andrew)
M1 <- gvisMap(Andrew, "LatLong" , "Tip", options=list(showTip=TRUE,
showLine=F, enableScrollWheel=TRUE,
mapType='satellite', useMapTypeControl=TRUE,
width=800,height=400))
plot(M1)
### RGOOGLEMAPS ###
library(RgoogleMaps)
# get maps from Google
newmap <- GetMap(center=c(53.343159,-6.251797), zoom =10, destfile = "newmap.png",
maptype = "satellite")
# View file in your wd
# now using bounding box instead of center coordinates:
newmap2 <- GetMap.bbox(lonR=c(-5, -6), latR=c(36, 37), destfile =
"newmap2.png", maptype="terrain") # try different maptypes
newmap3 <- GetMap.bbox(lonR=c(-5, -6), latR=c(36, 37), destfile =
"newmap3.png", maptype="satellite")
# and plot data onto these maps, e.g. these 3 points
PlotOnStaticMap(lat = c(53.3, 52.8, 53.4), lon = c(-6.5, -6.6, -6.8), zoom=
10, cex=2, pch= 19, col="red", FUN = points, add=F)