-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmaps.R
81 lines (63 loc) · 2.62 KB
/
maps.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
74
75
76
77
78
79
80
library(maptools)
shapefile_uru <- readShapeSpatial('shapefileUruguay/uruguay.shp',
proj4string = CRS("+proj=longlat +datum=WGS84"))
## unify polygons
install.packages("gpclib")
gpclibPermit()
shapefile_uru_union <- unionSpatialPolygons(shapefile_uru,
IDs = rep(1, length(shapefile_uru)))
library(ggplot2)
data_uru <- fortify(shapefile_uru_union)
# only Uruguay
map_uru <- ggplot(aes(x = long, y = lat, group = group, fill = id),
data = data_uru) +
geom_polygon(alpha = .6) +
geom_path(aes(x = long, y = lat, group = group),
data = data_uru,
colour = "purple") +
scale_fill_manual(values = c("purple"),
guide = FALSE) +
coord_equal()
# continent
library(ggmap)
continent <- qmap('uruguay', zoom = 3, maptype = 'watercolor')
# Uruguay in the continent
map_continent_uru <- continent +
geom_polygon(aes(x = long, y = lat, group = group, fill = id),
data = data_uru,
colour = 'purple',
alpha = .6) +
geom_path(aes(x = long, y = lat, group = group),
data = data_uru,
colour = "purple") +
scale_fill_manual(values = c("purple"),
guide = FALSE)
######## PARAGUAY
shapefile_par <- readShapeSpatial('shapefileParaguay/Departamentos de Paraguay/TodosDepartamentos.shp',
proj4string = CRS("+proj=longlat +datum=WGS84"))
## unify polygons
shapefile_par_union <- unionSpatialPolygons(shapefile_par, IDs = rep(2, length(shapefile_par)))
data_par <- fortify(shapefile_par_union)
# only Paraguay
map_par <- ggplot(aes(x = long, y = lat, group = group, fill = id),
data = data_par) +
geom_polygon(alpha = .6) +
geom_path(aes(x = long, y = lat, group = group), data = data_par,
colour = "purple") +
scale_fill_manual(values = c("purple"), guide = FALSE) +
coord_equal()
# Uruguay y Paraguay in the continent
map_continent_uru_par <- continent +
# Paraguay
geom_polygon(aes(x = long, y = lat, group = group, fill = id), data = data_par,
colour = 'blue', alpha = .4) +
geom_path(aes(x = long, y = lat, group = group), data = data_par,
colour = "blue") +
# Uruguay
geom_polygon(aes(x = long, y = lat, group = group, fill = id), data = data_uru,
colour = 'purple', alpha = .6) +
geom_path(aes(x = long, y = lat, group = group), data = data_uru,
colour = "purple") +
# Filling colors
scale_fill_manual(values = c("purple", "blue"), guide = FALSE)
save.image("uRuguayMap.Rdata")