-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMapsites_points.R
62 lines (51 loc) · 2.37 KB
/
Mapsites_points.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
#########
#Fraser Combe
##Making map in R with points
install.packages(c("cowplot", "googleway", "ggplot2", "ggrepel","ggspatial", "libwgeom", "sf", "rnaturalearth", "rnaturalearthdata","ggthemes"))
library("ggplot2")
library("sf")
library("rnaturalearth")
library("rnaturalearthdata")
library("ggthemes")
world <- ne_countries(scale = "medium", returnclass = "sf")
class(world)
ggplot(data = world) +
geom_sf()
library("ggspatial")
ggplot(data = world) +
geom_sf() +
annotation_scale(location = "bl", width_hint = 0.5) +
annotation_north_arrow(location = "bl", which_north = "true",
pad_x = unit(0.75, "in"), pad_y = unit(0.5, "in"),
style = north_arrow_fancy_orienteering) +
###This sets coords for boundaries of maps
coord_sf(xlim = c(-172.15, -79.12), ylim = c(19.97, 71.2), expand = FALSE)
##read in sites data here example Sorex Cinereus
##Column 1 Population column 2 Latitude column 3 Longitude (columns names must match in the script below)
sites<-read.csv(paste("~/sites_Sorex_C.csv", sep="" ))
##or
sites<-read.table(file.choose(), sep=",", header=TRUE )
sites
P<-ggplot(data = world) +
geom_sf(fill = "cornsilk") +
geom_jitter(data = sites, aes(x = Long, y = Lat,color = Pop, size =1.0,),position = position_jitter(width = 0.2, height = 0.1)) +
# shape = 23, fill = "darkred")
annotate(geom = "text", x = -168, y = 58, label = "Bering Sea",
fontface = "italic", color = "grey22", size = 5) +
annotate(geom = "text", x = -108, y = 60, label = "Canada",
fontface = "italic", color = "grey22", size = 5) +
annotate(geom = "text", x = -157, y = 63, label = "Alaska",
fontface = "italic", color = "grey22", size = 5) +
annotate(geom = "text", x = -130, y = 63, label = "Canada",
fontface = "italic", color = "grey22", size = 5) +
coord_sf(xlim = c(-175.15, -120.01), ylim = c(50, 75.2), expand = FALSE)+
xlab("Longitude") +
ylab("Latitude")+
ggtitle("Map of Sorex Cinereus sites")
P + theme(panel.grid.major = element_line(colour = gray(0.5), linetype = "dashed",
size = 0.5), panel.background = element_rect(fill = "aliceblue"),
panel.border = element_rect(fill = NA))
# If you want to color the labels manually use:
P + scale_color_manual(values=c("green", "red", "purple", "blue"))
P
dev.off()