Skip to content

Commit

Permalink
add script to make a map AND R
Browse files Browse the repository at this point in the history
  • Loading branch information
haganjam committed Jul 4, 2023
1 parent cd351db commit c3bb0c0
Show file tree
Hide file tree
Showing 2 changed files with 228 additions and 0 deletions.
165 changes: 165 additions & 0 deletions renv.lock
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,28 @@
"Repository": "CRAN",
"Hash": "68122010f01c4dcfbe58ce7112f2433d"
},
"DBI": {
"Package": "DBI",
"Version": "1.1.3",
"Source": "Repository",
"Repository": "CRAN",
"Requirements": [
"R",
"methods"
],
"Hash": "b2866e62bab9378c3cc9476a1954226b"
},
"KernSmooth": {
"Package": "KernSmooth",
"Version": "2.23-20",
"Source": "Repository",
"Repository": "CRAN",
"Requirements": [
"R",
"stats"
],
"Hash": "8dcfa99b14c296bc9f1fd64d52fd3ce7"
},
"MASS": {
"Package": "MASS",
"Version": "7.3-60",
Expand Down Expand Up @@ -398,6 +420,22 @@
],
"Hash": "8ae0d4328e2eb3a582dfd5391a3663b7"
},
"classInt": {
"Package": "classInt",
"Version": "0.4-9",
"Source": "Repository",
"Repository": "CRAN",
"Requirements": [
"KernSmooth",
"R",
"class",
"e1071",
"grDevices",
"graphics",
"stats"
],
"Hash": "bee651a42a89633eccb36dca9d9ab413"
},
"cli": {
"Package": "cli",
"Version": "3.6.1",
Expand Down Expand Up @@ -598,6 +636,22 @@
],
"Hash": "eb5742d256a0d9306d85ea68756d8187"
},
"e1071": {
"Package": "e1071",
"Version": "1.7-13",
"Source": "Repository",
"Repository": "CRAN",
"Requirements": [
"class",
"grDevices",
"graphics",
"methods",
"proxy",
"stats",
"utils"
],
"Hash": "1046cb48d06cb40c2900d8878f03a0fe"
},
"ellipsis": {
"Package": "ellipsis",
"Version": "0.3.2",
Expand Down Expand Up @@ -1527,6 +1581,18 @@
],
"Hash": "14dc9f7a3c91ebb14ec5bb9208a07061"
},
"proxy": {
"Package": "proxy",
"Version": "0.4-27",
"Source": "Repository",
"Repository": "CRAN",
"Requirements": [
"R",
"stats",
"utils"
],
"Hash": "e0ef355c12942cf7a6b91a6cfaea8b3e"
},
"ps": {
"Package": "ps",
"Version": "1.7.3",
Expand Down Expand Up @@ -1581,6 +1647,20 @@
],
"Hash": "5e3c5dc0b071b21fa128676560dbe94d"
},
"raster": {
"Package": "raster",
"Version": "3.6-20",
"Source": "Repository",
"Repository": "CRAN",
"Requirements": [
"R",
"Rcpp",
"methods",
"sp",
"terra"
],
"Hash": "ebebd9f0f203a129eb2da96470191b82"
},
"readr": {
"Package": "readr",
"Version": "2.1.4",
Expand Down Expand Up @@ -1744,6 +1824,18 @@
"Repository": "CRAN",
"Hash": "690bd2acc42a9166ce34845884459320"
},
"s2": {
"Package": "s2",
"Version": "1.1.4",
"Source": "Repository",
"Repository": "CRAN",
"Requirements": [
"R",
"Rcpp",
"wk"
],
"Hash": "f1cbe03bb3346f8e817518ffa20f9f5a"
},
"sass": {
"Package": "sass",
"Version": "0.4.5",
Expand Down Expand Up @@ -1776,6 +1868,29 @@
],
"Hash": "906cb23d2f1c5680b8ce439b44c6fa63"
},
"sf": {
"Package": "sf",
"Version": "1.0-13",
"Source": "Repository",
"Repository": "CRAN",
"Requirements": [
"DBI",
"R",
"Rcpp",
"classInt",
"grDevices",
"graphics",
"grid",
"magrittr",
"methods",
"s2",
"stats",
"tools",
"units",
"utils"
],
"Hash": "8fb4839843abc03528ff9f86424d6acd"
},
"som": {
"Package": "som",
"Version": "0.3-5.1",
Expand Down Expand Up @@ -1804,6 +1919,23 @@
],
"Hash": "1237ef6b70a56338cf41f81ae540dbd4"
},
"sp": {
"Package": "sp",
"Version": "2.0-0",
"Source": "Repository",
"Repository": "CRAN",
"Requirements": [
"R",
"grDevices",
"graphics",
"grid",
"lattice",
"methods",
"stats",
"utils"
],
"Hash": "2551981e6f85d59c81652bf654d6c3ca"
},
"stringi": {
"Package": "stringi",
"Version": "1.7.12",
Expand Down Expand Up @@ -1864,6 +1996,18 @@
"Repository": "CRAN",
"Hash": "34c16f1ef796057bfa06d3f4ff818a5d"
},
"terra": {
"Package": "terra",
"Version": "1.7-39",
"Source": "Repository",
"Repository": "CRAN",
"Requirements": [
"R",
"Rcpp",
"methods"
],
"Hash": "6037d18193ca3f16900646e773937094"
},
"testthat": {
"Package": "testthat",
"Version": "3.1.7",
Expand Down Expand Up @@ -1984,6 +2128,17 @@
],
"Hash": "b2e1cbce7c903eaf23ec05c58e59fb5e"
},
"units": {
"Package": "units",
"Version": "0.8-2",
"Source": "Repository",
"Repository": "CRAN",
"Requirements": [
"R",
"Rcpp"
],
"Hash": "422376fe53419adcde4710d43acbcdd0"
},
"utf8": {
"Package": "utf8",
"Version": "1.2.3",
Expand Down Expand Up @@ -2121,6 +2276,16 @@
],
"Hash": "c0e49a9760983e81e55cdd9be92e7182"
},
"wk": {
"Package": "wk",
"Version": "0.7.3",
"Source": "Repository",
"Repository": "CRAN",
"Requirements": [
"R"
],
"Hash": "68a7ab6ec1afb5f076172b983c069313"
},
"xfun": {
"Package": "xfun",
"Version": "0.38",
Expand Down
63 changes: 63 additions & 0 deletions scripts/03_empirical_analysis/03_maps/01_map_study_sites.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@

# map the study sites
library(sp)
library(sf)
library(raster)
library(dplyr)
library(readr)
library(ggplot2)

# load the Swedish coastline
swe_coast <- st_read("data/GIS_layers/Sweden_coast/land_skagerrak_kattegat.shp")
projection(swe_coast)

# convert to wgs84 coordinate lat lon reference system
swe_coast <- st_transform(swe_coast, crs = "+proj=longlat +datum=WGS84 +no_defs")

# plot the Swedish coastline
# plot(swe_coast)

# get a map of just the Tjarno region
tja_coast <- st_crop(swe_coast, xmin = 11, xmax = 11.3, ymin = 58, ymax = 59)
plot(tja_coast, col = "white", bg = "white", main = NULL)

# get the coordinates of the sampling points
cs2 <- read_csv("data/case_study_2/ResearchBox 843/Data/site_data.csv")
head(cs2)

# get the latitude-longitude coordinates
cs2 <- dplyr::select(cs2, cluster_id, dec_lat, dec_lon)
head(cs2)

# get the unique cluster ids
cs2 <-
cs2 %>%
group_by(cluster_id) %>%
summarise(dec_lat = mean(dec_lat),
dec_lon = mean(dec_lon))

# remove the cluster F because we did not use it
cs2 <-
cs2 %>%
filter(cluster_id != "F")

# rename the columns
cs2_pts <-
cs2 %>%
dplyr::select(dec_lon, dec_lat)
names(cs2_pts) <- c("longitude", "latitude")

# Convert data frame to sf object
cs2_pts <- st_as_sf(x = cs2_pts, coords = c("longitude", "latitude"), crs = st_crs(swe_coast))

# plot the points
plot(tja_coast, col = "white")
points(cs2_pts, col = "red")

ggplot() +
geom_sf(data = tja_coast) +
geom_sf(data = cs2_pts)




0 comments on commit c3bb0c0

Please sign in to comment.