-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMaps_Fig1.Rmd
74 lines (56 loc) · 2.43 KB
/
Maps_Fig1.Rmd
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
---
title: "Maps"
author: "Shankar K Shakya"
date: "August 22, 2017"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r, warning=FALSE}
library(ggplot2)
library(raster)
library(gridExtra)
library(grid)
library(maptools)
mx <- readShapePoly("mexstates/mexstates.shp")
mystates <- mx[grep("Mexico|Tlaxcala|Michoacan", mx@data$ADMIN_NAME),]
states <- coordinates(mystates)
states <- data.frame(states)
states$label <- mystates@data$ADMIN_NAME
site <- read.csv("Dgeo_MX.csv", header = TRUE)
colnames(site) <- c("label", "X2", "X1")
states <- rbind(states, site[c(3,1,2)])
states <- states[4:9, ]
colnames(states)[3] <- "Sites"
pol <- data.frame(xmin=-103.7455,xmax=-97.61348 ,ymin=17.92083 ,ymax=20.39417)
mystates <- fortify(mystates)
colnames(mystates)[6] <- "States"
head(mystates)
mystates$States[mystates$States == 18] <- "Michoacan"
mystates$States[mystates$States == 19] <- "Central Mexico"
mystates$States[mystates$States == 20] <- "Tlaxcala"
mycol <- rainbow(6)
mycol[2] <- "#000000"
statemap <- ggplot() +
geom_polygon(data=mystates, aes(x = long, y = lat, group=group, fill = States)) +
coord_equal() +
theme_bw() + labs(x="Longitude", y = "Latitude") +
geom_point(data = states, aes(x=X1, y=X2, color = Sites), size = 1.9) +
scale_color_manual(values = mycol) +
theme(axis.text = element_text(size = 10, face = "bold", family = "Microsoft Sans Serif", colour = "black")) +
theme(axis.title = element_text(size = 10, face = "bold", family = "Microsoft Sans Serif")) +
theme(text = element_text(size =10, face = "bold", family = "Microsoft Sans Serif", colour = "black")) +
theme(plot.margin=unit(c(0,0,0,0),"mm"))
statemap
#ggsave("statemap.tiff", plot = last_plot(), width = 7, height = 3.5, dpi = 600)
mx_map <- ggplot()+
geom_polygon(data=mx, aes(long,lat,group=group),colour="grey10",fill="#fff7bc") +
coord_equal()+
theme_bw()+labs(x="Longitude",y = "Latitude") +
geom_rect(data = pol, aes(xmin = xmin, xmax = xmax, ymin = ymin, ymax = ymax), alpha=0, colour="red", size = 1, linetype = 1) +
theme(axis.text = element_text(size =10, face = "bold", family = "Microsoft Sans Serif", colour = "black")) +
theme(axis.title = element_text(size = 10, face = "bold", family = "Microsoft Sans Serif", colour = "black"))
#ggsave("insetmx_map.tiff", plot = last_plot(), height = 3, width = 4, dpi = 600)
mx_map
```