Last updated: 2021-04-24
Checks: 6 1
Knit directory: wildlife-bacteria/
This reproducible R Markdown analysis was created with workflowr (version 1.6.2). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.
The R Markdown file has staged changes. To know which version of the R Markdown file created these results, you’ll want to first commit it to the Git repo. If you’re still working on the analysis, you can ignore this warning. When you’re finished, you can run wflow_publish
to commit the R Markdown file and build the HTML.
Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.
The command set.seed(20210129)
was run prior to running the code in the R Markdown file. Setting a seed ensures that any results that rely on randomness, e.g. subsampling or permutations, are reproducible.
Great job! Recording the operating system, R version, and package versions is critical for reproducibility.
Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.
Great job! Using relative paths to the files within your workflowr project makes it easier to run your code on other machines.
Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility.
The results in this page were generated with repository version a0173d4. See the Past versions tab to see a history of the changes made to the R Markdown and HTML files.
Note that you need to be careful to ensure that all relevant files for the analysis have been committed to Git prior to generating the results (you can use wflow_publish
or wflow_git_commit
). workflowr only checks the R Markdown file, but you know if there are other scripts or data files that it depends on. Below is the status of the Git repository when the results were generated:
Ignored files:
Ignored: .DS_Store
Ignored: .Rhistory
Ignored: .Rproj.user/
Ignored: analysis/.DS_Store
Ignored: data/.DS_Store
Ignored: output/.DS_Store
Untracked files:
Untracked: NCBI_data/
Untracked: RData/
Untracked: analysis/microbiome-viz-extra.Rmd
Untracked: analysis/phylogeny.Rmd
Untracked: analysis/tois.Rmd
Untracked: data/dada2/
Untracked: data/dada2_tois/
Untracked: data/site_map.xlsx
Untracked: data/taxa_trees/
Untracked: data/tmp/
Untracked: output/beta-div-statistics.txt
Untracked: output/plots/
Untracked: output/supp_table_pos.xlsx
Untracked: tmp/
Unstaged changes:
Modified: analysis/QIIME2.Rmd
Modified: analysis/_site.yml
Modified: analysis/microbiome-viz.Rmd
Modified: analysis/phyloseq.Rmd
Modified: analysis/site-map.Rmd
Deleted: data/ps_bact_samp.RData
Deleted: data/ps_dec_bact.RData
Staged changes:
Modified: analysis/index.Rmd
Modified: analysis/microbiome-viz.Rmd
Modified: analysis/phyloseq.Rmd
New: analysis/site-map.Rmd
New: code/taxa_summary.R
New: data/ps_bact_samp.RData
New: data/ps_dec_bact.RData
Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.
There are no past versions. Publish this analysis with wflow_publish()
to start tracking its development.
ozmaps
#ozmaps data not on CRAN
#devtools::install_github("mdsumner/ozmaps.data")
Load libraries
pkgs <- c("ozmaps", "sf", "sp", "dplyr", "rgdal",
"raster", "ggplot2", "viridis", "readr",
"paletteer", "rmapshaper", "ggrepel",
"tidyverse", "ozmaps.data", "readxl")
lapply(pkgs, require, character.only = TRUE)
Import data
site_map <- read_excel("data/site_map.xlsx")
site_map_lab = column_to_rownames(site_map, var = "Site name")
site_map <- read_excel(“data/site_map.xlsx”, col_types = c(“text”, “text”, “numeric”, “numeric”, “text”, “numeric”))
Ozmaps
Simple Aus map
ozmap()
Plot of states
sf_oz <- ozmap_data("states")
if (utils::packageVersion("paletteer") < '1.0.0') {
pal <- paletteer::paletteer_d(package = "ochRe", palette = "namatjira_qual")
} else {
pal <- paletteer::paletteer_d(palette = "ochRe::namatjira_qual")
}
mycols = c("#a19a11", "#D3D3D3", "#D3D3D3", "#D3D3D3", "#D3D3D3", "#D3D3D3", "#D3D3D3", "#365350", "#a19a11", "#3f4482")
opal <- colorRampPalette(pal)
nmjr <- opal(nrow(sf_oz))
plot(st_geometry(sf_oz), col = mycols)
Plot the ABS layers (from 2016).
ozmap("abs_ced", col = opal(nrow(abs_ced)))
Plot of map with city regions abs_gccsa
citycols = c("#D3D3D3", "#3f4482", "#D3D3D3", "#D3D3D3", "#D3D3D3", "#D3D3D3", "#D3D3D3", "#D3D3D3", "#3f4482", "#D3D3D3", "#D3D3D3", "#D3D3D3", "#D3D3D3", "#D3D3D3", "#D3D3D3", "#D3D3D3")
plot(st_transform(abs_gccsa, LCC), main = "Greater Capital City Statistical Areas", col = citycols)
Enlarge northern beaches
library(dplyr)
kbor <- abs_lga %>% dplyr::filter(grepl("Northern Beaches", NAME))
bb <- st_bbox(kbor)
layout(matrix(c(1, 1, 1, 2, 2, 2, 2, 2, 2), nrow = 3))
plot(kbor, reset = FALSE, main = "Northern Beaches (NSW)")
rect(bb["xmin"], bb["ymin"], bb["xmax"], bb["ymax"])
library(mapdata)
#> Loading required package: maps
par(mar = rep(0, 4))
plot(c(110, 160), c(-45, -5), type = "n", asp = 1/cos(mean(bb[c(2, 4)]) * pi/180), axes = FALSE, xlab = "", ylab = "")
plot = maps::map(database = "worldHires", regions = "australia", xlim = c(110, 160), ylim = c(-45, -5), add = TRUE)
rect(bb["xmin"], bb["ymin"], bb["xmax"], bb["ymax"])
buffer <- 0.11
min_lon <- 110
max_lon <- 160
min_lat <- -45
max_lat <- -5
geo_bounds <- c(left = min_lon, bottom = min_lat, right = max_lon, top = max_lat)
oz_states <- ozmaps::ozmap_states
ggplot(oz_states) +
geom_sf() +
coord_sf()
oz_states <- ozmaps::ozmap_states %>% filter(NAME != "Other Territories")
oz_votes <- rmapshaper::ms_simplify(ozmaps::abs_ced)
ggplot() +
geom_sf(data = oz_states, mapping = aes(fill = NAME), show.legend = FALSE) +
geom_sf(data = oz_votes, fill = NA) +
coord_sf()
# large map
map1 = ggplot() +
geom_sf(data = oz_votes) +
geom_sf(data = oz_states, colour = "black", fill = "NA") +
geom_point(data = site_map_lab, mapping = aes(x = lon, y = lat, color = Site, shape=Site, size= Size)) +
coord_sf() + theme_classic() + theme(legend.position = "none", axis.title.x = element_blank(), axis.title.y = element_blank()) + scale_color_manual(values=c("#E69F00", "#56B4E9")) + scale_shape_manual(values=c(8, 16)) + xlim (114,155)
# base map for inserts
map2 = ggplot() +
geom_sf(data = oz_votes) +
geom_sf(data = oz_states, colour = "black", fill = "NA") +
geom_point(data = site_map_lab, mapping = aes(x = lon, y = lat, color = Site, shape=Site, size= Size)) +
coord_sf() + theme_classic() + theme(legend.position = "none", axis.title.x = element_blank(), axis.title.y = element_blank()) + scale_color_manual(values=c("#999999", "#E69F00"))
# zoom in on Sydney region
map3 = map2 + coord_sf(xlim = c(150, 152), ylim = c(-35, -33.0)) + theme(legend.position = "none") + theme(axis.title.x = element_blank(), axis.title.y = element_blank())
map4 = map2 + coord_sf(xlim = c(115, 117), ylim = c(-32.5, -31)) + theme(legend.position = "none") + theme(axis.title.x = element_blank(), axis.title.y = element_blank())
ggsave("map_base.pdf", plot = map1, path = "output/plots", width = 30, height = 15, units = "cm")
ggsave("map_NSW.pdf", plot = map3, path = "output/plots", width = 10, height = 10, units = "cm")
ggsave("map_WA.pdf", plot = map4, path = "output/plots", width = 10, height = 10, units = "cm")
Capital cities
oz_capitals <- tibble::tribble(
~city, ~lat, ~lon,
"Sydney", -33.8688, 151.2093,
"Melbourne", -37.8136, 144.9631,
"Brisbane", -27.4698, 153.0251,
"Adelaide", -34.9285, 138.6007,
"Perth", -31.9505, 115.8605,
"Hobart", -42.8821, 147.3272,
"Canberra", -35.2809, 149.1300,
"Darwin", -12.4634, 130.8456,
)
Following tutorial at this link
Load libraries
pkgs <- c("sp", "dplyr", "rgdal",
"raster", "ggplot2", "readxl",
"viridis", "readr")
lapply(pkgs, require, character.only = TRUE)
Load your point data file
site_map <- read_excel("data/site_map.xlsx")
Create buffer around your data points
# Make boundaries
buffer <- 0.11
min_lon <- 110
max_lon <- 160
min_lat <- -45
max_lat <- -5
geo_bounds <- c(left = min_lon, bottom = min_lat, right = max_lon, top = max_lat)
# Now map with boundaries
Sites.grid <- expand.grid(lon_bound = c(geo_bounds[1], geo_bounds[3]),
lat_bound = c(geo_bounds[2], geo_bounds[4]))
coordinates(Sites.grid) <- ~ lon_bound + lat_bound
Load mapping files Downloaded from GEODATA COAST 100K 2004 shapefiles available here
Aus <- readOGR(dsn = "~/Documents/Programs/R/Maps/Rpackage_Geodata-coast/australia",layer = "cstauscd_r")
Remove coastline clutter from map
Aus_coast <- subset(Aus, FEAT_CODE != "sea")
plot <- plot(Aus_coast)
Now apply boundaries to the map without coastline
Aus_crop <- crop(Aus_coast, extent(Sites.grid))
plot(Aus_crop)
Plot map with axis
aus_plot1 <- ggplot() +
geom_polygon(data = Aus_crop, aes(x=long, y=lat, group=group), fill = "gray98", colour="black") +
coord_equal() +
labs(x="Longitude", y="Latitude") +
theme_classic()
aus_plot2 = aus_plot1 + geom_point(data = site_map, aes (x=lon, y=lat, color=Site, stroke=1)) +
geom_text(label=(site_map$Site)) + scale_color_brewer(palette = "Set1") + theme_classic()
ggsave("aus_plot2.pdf", plot = aus_plot2, path = "output/plots", width = 15, height = 15, units = "cm")
# load library
library(OpenStreetMap)
# extract map
AustraliaMap <- openmap(c(-8,110),
c(-45,160),
# type = "osm",
# type = "esri",
type = "nps",
minNumTiles=7)
plot(AustraliaMap)
library(DT)
opt <- c("osm", "osm-bw","maptoolkit-topo", "waze", "bing", "stamen-toner", "stamen-terrain", "stamen-watercolor", "osm-german", "osm-wanderreitkarte", "mapbox", "esri", "esri-topo", "nps", "apple-iphoto", "skobbler", "hillshade", "opencyclemap", "osm-transport", "osm-public-transport", "osm-bbike", "osm-bbike-german")
opt <- data.frame(opt)
# extract map
queensland1 <- openmap(c(-8,135),
c(-30,160),
type = "osm",
minNumTiles=6)
queensland2 <- openmap(c(-8,135),
c(-30,160),
type = "esri",
minNumTiles=6)
# plot maps
par(mfrow = c(1, 2)) # display plots in 1 row/2 columns
plot(queensland1); plot(queensland2); par(mfrow = c(1, 1)) # restore original settings
Leaflet here
# load package
library(leaflet)
# load library
m <- leaflet() %>% setView(lng = 153.05, lat = -27.45, zoom = 12)
# display map
m %>% addTiles()
# add ERSI theme
esri <- grep("^Esri", providers, value = TRUE)
m %>% addTiles() %>% addLayersControl(baseGroups = names(esri))
leaflet(data = site_map) %>% addTiles() %>%
addMarkers(~lon, ~lat, icon=oceanIcons)