Creation date: 2025/08/04 Modified Date & Time: 2025/08/27 @ 07:29
library(shiny)
library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
## ✔ ggplot2 3.4.0 ✔ purrr 0.3.5
## ✔ tibble 3.1.8 ✔ dplyr 1.0.10
## ✔ tidyr 1.2.1 ✔ stringr 1.4.1
## ✔ readr 2.1.3 ✔ forcats 0.5.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
library(plotly)
##
## Attaching package: 'plotly'
##
## The following object is masked from 'package:ggplot2':
##
## last_plot
##
## The following object is masked from 'package:stats':
##
## filter
##
## The following object is masked from 'package:graphics':
##
## layout
TEST-GOE-Monitor.xlsx
file, with one worksheet for Data, and one worksheet for Site infoSite-Data-TEST-GOE-Monitor.csv
& SiteData-TEST-GOE-Monitor.csv
TEST-GOE-Monitor.xlsx
excel file first, then resave as csv# Site Data
geo_eccc <- read.csv("SiteData-TEST-GOE-Monitor.csv", header = TRUE, sep = ",")
# Site Details
Sites_eccc <- read.csv("SiteDetails-TEST-GOE-Monitor.csv", header = TRUE, sep = ",")
colnames(geo_eccc)
## [1] "Subregion" "Site"
## [3] "Proportion_of_native_species" "Cultural_species_richness"
## [5] "Exotic_species" "Trampling"
## [7] "Herbivory" "Composite_Index"
## [9] "Year"
colnames(Sites_eccc)
## [1] "Subregion" "Site" "Land.Manager"
## [4] "Main.Restoration.Type" "Restoration.Intensity" "Area.ha"
## [7] "Lat" "Lng"
# using scales creates % character instead of number
# Percentage_of_native_species <- scales::percent(geo_eccc$Proportion_of_native_species)
# Percentage_of_native_species
Percentage_ns <- geo_eccc$Proportion_of_native_species * 100
Percentage_ns
## [1] 94 55 77 66 75 53 45 65 62 58 45 67 62 61 32 64 49 41 47 34 34 44 54 37
Percentage_ns
data to columndata
# https://sparkbyexamples.com/r-programming/add-column-to-dataframe-in-r/
# geo_eccc_1 <- cbind(geo_eccc, Percentage_of_native_species)
# geo_eccc_1
geo_eccc <- cbind(geo_eccc, Percentage_ns)
geo_eccc
## Subregion Site Proportion_of_native_species
## 1 Gulf Islands Anniversary Island 0.94
## 2 Gulf Islands AVNR 0.55
## 3 Gulf Islands Brackman Island 0.77
## 4 Gulf Islands Crows Nest 0.66
## 5 Gulf Islands Dock Islet N 0.75
## 6 Gulf Islands Eagle Islet 0.53
## 7 Gulf Islands Mt Maxwell 0.45
## 8 Gulf Islands Owl Islet 0.65
## 9 Gulf Islands Reay Islet 0.62
## 10 Gulf Islands Retreat Island 0.58
## 11 Gulf Islands Rum Islet 0.45
## 12 Gulf Islands SISCENEM 0.67
## 13 Saanich Peninsula Bear Hill Park 0.62
## 14 Saanich Peninsula Camas Hill 0.61
## 15 Saanich Peninsula Gonzales Hill Park 0.32
## 16 Saanich Peninsula Gore Park 0.64
## 17 Saanich Peninsula Highrock Park 0.49
## 18 Saanich Peninsula Mill Hill Park 0.41
## 19 Saanich Peninsula Oak Haven Park 0.47
## 20 Saanich Peninsula Scafe Hill 0.34
## 21 Saanich Peninsula Seymour Hill 0.34
## 22 Saanich Peninsula Stewart Hill 0.44
## 23 Saanich Peninsula Trial Island 0.54
## 24 Saanich Peninsula Uplands Park 0.37
## Cultural_species_richness Exotic_species Trampling Herbivory Composite_Index
## 1 2.71 0.17 5.00 1.14 1.8
## 2 1.30 57.19 4.70 36.50 0.6
## 3 2.80 11.17 5.40 0.00 2.0
## 4 1.07 31.51 1.64 26.71 1.0
## 5 3.60 8.80 12.20 0.10 1.6
## 6 0.80 28.25 16.60 0.00 0.8
## 7 0.42 64.30 10.00 6.00 0.2
## 8 2.00 27.72 10.67 0.67 1.4
## 9 3.60 11.51 11.00 8.00 1.0
## 10 2.33 33.00 32.33 0.00 1.0
## 11 1.00 73.21 22.20 70.80 0.0
## 12 3.40 16.12 12.80 0.50 1.6
## 13 1.86 24.46 7.57 9.50 1.0
## 14 2.43 27.19 7.71 4.71 1.4
## 15 1.00 83.16 10.40 1.20 0.4
## 16 4.40 7.35 6.20 1.60 1.6
## 17 1.60 37.10 8.20 1.20 1.0
## 18 1.56 46.33 14.33 25.67 0.4
## 19 1.50 34.60 1.88 12.75 1.0
## 20 1.40 55.35 10.20 1.40 0.4
## 21 2.20 65.99 9.20 0.20 0.8
## 22 1.00 79.56 4.80 0.80 0.6
## 23 3.57 30.73 2.00 0.14 1.6
## 24 1.45 49.38 2.36 5.82 1.0
## Year Percentage_ns
## 1 2023 94
## 2 2023 55
## 3 2023 77
## 4 2023 66
## 5 2023 75
## 6 2023 53
## 7 2023 45
## 8 2023 65
## 9 2023 62
## 10 2023 58
## 11 2023 45
## 12 2023 67
## 13 2023 62
## 14 2023 61
## 15 2023 32
## 16 2023 64
## 17 2023 49
## 18 2023 41
## 19 2023 47
## 20 2023 34
## 21 2023 34
## 22 2023 44
## 23 2023 54
## 24 2023 37
str(geo_eccc)
## 'data.frame': 24 obs. of 10 variables:
## $ Subregion : chr "Gulf Islands" "Gulf Islands" "Gulf Islands" "Gulf Islands" ...
## $ Site : chr "Anniversary Island" "AVNR" "Brackman Island" "Crows Nest" ...
## $ Proportion_of_native_species: num 0.94 0.55 0.77 0.66 0.75 0.53 0.45 0.65 0.62 0.58 ...
## $ Cultural_species_richness : num 2.71 1.3 2.8 1.07 3.6 0.8 0.42 2 3.6 2.33 ...
## $ Exotic_species : num 0.17 57.19 11.17 31.51 8.8 ...
## $ Trampling : num 5 4.7 5.4 1.64 12.2 ...
## $ Herbivory : num 1.14 36.5 0 26.71 0.1 ...
## $ Composite_Index : num 1.8 0.6 2 1 1.6 0.8 0.2 1.4 1 1 ...
## $ Year : int 2023 2023 2023 2023 2023 2023 2023 2023 2023 2023 ...
## $ Percentage_ns : num 94 55 77 66 75 53 45 65 62 58 ...
str(geo_eccc)
## 'data.frame': 24 obs. of 10 variables:
## $ Subregion : chr "Gulf Islands" "Gulf Islands" "Gulf Islands" "Gulf Islands" ...
## $ Site : chr "Anniversary Island" "AVNR" "Brackman Island" "Crows Nest" ...
## $ Proportion_of_native_species: num 0.94 0.55 0.77 0.66 0.75 0.53 0.45 0.65 0.62 0.58 ...
## $ Cultural_species_richness : num 2.71 1.3 2.8 1.07 3.6 0.8 0.42 2 3.6 2.33 ...
## $ Exotic_species : num 0.17 57.19 11.17 31.51 8.8 ...
## $ Trampling : num 5 4.7 5.4 1.64 12.2 ...
## $ Herbivory : num 1.14 36.5 0 26.71 0.1 ...
## $ Composite_Index : num 1.8 0.6 2 1 1.6 0.8 0.2 1.4 1 1 ...
## $ Year : int 2023 2023 2023 2023 2023 2023 2023 2023 2023 2023 ...
## $ Percentage_ns : num 94 55 77 66 75 53 45 65 62 58 ...
str(Sites_eccc)
## 'data.frame': 24 obs. of 8 variables:
## $ Subregion : chr "Saanich Peninsula" "Saanich Peninsula" "Saanich Peninsula" "Saanich Peninsula" ...
## $ Site : chr "Gore Park" "Highrock Park" "Mill Hill Park" "Oak Haven Park" ...
## $ Land.Manager : chr "Central Saanich" "City of Esquimalt" "CRD" "CRD" ...
## $ Main.Restoration.Type: chr "invasive removal" "invasive removal" "invasive removal" "invasive removal" ...
## $ Restoration.Intensity: chr "moderate" "low" "high" "high" ...
## $ Area.ha : num 0.74 2.88 16.66 3.16 3.36 ...
## $ Lat : num 48.5 48.4 48.5 48.6 48.5 ...
## $ Lng : num -123 -123 -123 -123 -123 ...
length(unique(geo_eccc$Site))
## [1] 24
length(unique(Sites_eccc$Site))
## [1] 24
# tidyverse
# https://stackoverflow.com/questions/68989228/sort-dataframe-by-column-value-r
Sites_eccc_1 <- Sites_eccc %>% arrange(Sites_eccc$Site)
geo_eccc_1 <- geo_eccc %>% arrange(geo_eccc$Site)
merge
doesn’t work, leaves columns empty)geo_eccc_sites <- cbind(Sites_eccc_1, geo_eccc_1)
names(geo_eccc_sites)
## [1] "Subregion" "Site"
## [3] "Land.Manager" "Main.Restoration.Type"
## [5] "Restoration.Intensity" "Area.ha"
## [7] "Lat" "Lng"
## [9] "Subregion" "Site"
## [11] "Proportion_of_native_species" "Cultural_species_richness"
## [13] "Exotic_species" "Trampling"
## [15] "Herbivory" "Composite_Index"
## [17] "Year" "Percentage_ns"
# https://stackoverflow.com/questions/7072159/how-do-you-remove-columns-from-a-data-frame
geo_eccc_sites_1 <- geo_eccc_sites[c(-9,-10)]
names(geo_eccc_sites_1)
## [1] "Subregion" "Site"
## [3] "Land.Manager" "Main.Restoration.Type"
## [5] "Restoration.Intensity" "Area.ha"
## [7] "Lat" "Lng"
## [9] "Proportion_of_native_species" "Cultural_species_richness"
## [11] "Exotic_species" "Trampling"
## [13] "Herbivory" "Composite_Index"
## [15] "Year" "Percentage_ns"
names(geo_eccc_sites_1)[names(geo_eccc_sites_1) == "Land.Manager"] <- "Land_Manager"
names(geo_eccc_sites_1)[names(geo_eccc_sites_1) == "Main.Restoration.Type"] <- "Main_Restoration_Type"
names(geo_eccc_sites_1)[names(geo_eccc_sites_1) == "Restoration.Intensity"] <- "Restoration_Intensity"
names(geo_eccc_sites_1)[names(geo_eccc_sites_1) == "Area.ha"] <- "Area_ha"
names(geo_eccc_sites_1)
## [1] "Subregion" "Site"
## [3] "Land_Manager" "Main_Restoration_Type"
## [5] "Restoration_Intensity" "Area_ha"
## [7] "Lat" "Lng"
## [9] "Proportion_of_native_species" "Cultural_species_richness"
## [11] "Exotic_species" "Trampling"
## [13] "Herbivory" "Composite_Index"
## [15] "Year" "Percentage_ns"
write.csv(geo_eccc_sites_1, "geo_eccc_all_site_data.csv", row.names = FALSE)
site_natsp <- ggplot(geo_eccc,
aes(x = Site, y = Percentage_ns)) +
geom_point(shape = 18, size = 2) +
theme_minimal() + #get rid of grey background and tick marks
theme(legend.position="none") + #remove legend
theme(axis.text.x = element_text(angle = 25, vjust = 1, hjust=1, size = 7)) +
labs(title='Plotting Site by Percentage Native Species',
subtitle='ECCC',
caption = "Chart by Wendy Anthony \n 2025-08-04")
site_natsp
site_natsp <- ggplot(geo_eccc,
aes(x = Site, y = Composite_Index)) +
geom_point(shape = 18, size = 2) +
theme_minimal() + #get rid of grey background and tick marks
theme(legend.position="none") + #remove legend
theme(axis.text.x = element_text(angle = 25, vjust = 1, hjust=1, size = 7)) +
labs(title='Plotting Site by Composite Index',
subtitle='ECCC',
caption = "Chart by Wendy Anthony \n 2025-08-04")
site_natsp
TEST
# names(geo_eccc_sites_1)
# str(geo_eccc_sites_1)
# unique(geo_eccc_sites_1$Restoration_Intensity)
#
# # change character to factor
# geo_eccc_sites_1$Restoration_Intensity <- as.factor(geo_eccc_sites_1$Restoration_Intensity)
# # change factor to character
# geo_eccc_sites_1 <- data.frame(lapply(geo_eccc_sites_1, as.character), stringsAsFactors=FALSE)
#
# # WORKS !!!
# Restoration_Intensity_order <- c("high", "moderate", "low", "minimal")
# arranged_geo_eccc_sites_1 <- geo_eccc_sites_1 %>%
# arrange(factor(Restoration_Intensity, levels = Restoration_Intensity_order))
# arranged_geo_eccc_sites_1
# str(arranged_geo_eccc_sites_1)
#
# # still not showing the order
# site_restInt <- ggplot(arranged_geo_eccc_sites_1,
# aes(x = Site, y = Restoration_Intensity, color = Subregion)) +
# geom_point(shape = 18, size = 2) +
# #geom_bar(stat="identity") +
# theme_minimal() + #get rid of grey background and tick marks
# theme(legend.position="bottom") + #remove legend
# theme(axis.text.x = element_text(angle = 25, vjust = 1, hjust=1, size = 7)) +
# labs(title='Plotting Site by Restoration_Intensity',
# subtitle='ECCC',
# caption = "Chart by Wendy Anthony \n 2025-08-20")
# site_restInt
# ggplotly(site_restInt)
names(geo_eccc_sites_1)
## [1] "Subregion" "Site"
## [3] "Land_Manager" "Main_Restoration_Type"
## [5] "Restoration_Intensity" "Area_ha"
## [7] "Lat" "Lng"
## [9] "Proportion_of_native_species" "Cultural_species_richness"
## [11] "Exotic_species" "Trampling"
## [13] "Herbivory" "Composite_Index"
## [15] "Year" "Percentage_ns"
str(geo_eccc_sites_1)
## 'data.frame': 24 obs. of 16 variables:
## $ Subregion : chr "Gulf Islands" "Gulf Islands" "Saanich Peninsula" "Gulf Islands" ...
## $ Site : chr "Anniversary Island" "AVNR" "Bear Hill Park" "Brackman Island" ...
## $ Land_Manager : chr "GINPR" "Saltspring conservancy" "CRD" "GINPR" ...
## $ Main_Restoration_Type : chr "herbivore reduction" "herbivore reduction" "invasive removal" "invasive removal" ...
## $ Restoration_Intensity : chr "high" "minimal" "low" "high" ...
## $ Area_ha : num 4.39 20.54 3.8 4.41 10.1 ...
## $ Lat : num 48.8 48.8 48.5 48.7 48.4 ...
## $ Lng : num -123 -123 -123 -123 -124 ...
## $ Proportion_of_native_species: num 0.94 0.55 0.62 0.77 0.61 0.66 0.75 0.53 0.32 0.64 ...
## $ Cultural_species_richness : num 2.71 1.3 1.86 2.8 2.43 1.07 3.6 0.8 1 4.4 ...
## $ Exotic_species : num 0.17 57.19 24.46 11.17 27.19 ...
## $ Trampling : num 5 4.7 7.57 5.4 7.71 1.64 12.2 16.6 10.4 6.2 ...
## $ Herbivory : num 1.14 36.5 9.5 0 4.71 ...
## $ Composite_Index : num 1.8 0.6 1 2 1.4 1 1.6 0.8 0.4 1.6 ...
## $ Year : int 2023 2023 2023 2023 2023 2023 2023 2023 2023 2023 ...
## $ Percentage_ns : num 94 55 62 77 61 66 75 53 32 64 ...
# Step 1
desired_levels <- c("high", "moderate", "low", "minimal")
# create new df to create desired levels
geo_eccc_sites_2 <- geo_eccc_sites_1
# this changes data type from character to factor
geo_eccc_sites_2$Restoration_Intensity <- factor(geo_eccc_sites_1$Restoration_Intensity, levels = desired_levels)
print(levels(geo_eccc_sites_2$Restoration_Intensity)) # New order of levels
## [1] "high" "moderate" "low" "minimal"
str(geo_eccc_sites_2)
## 'data.frame': 24 obs. of 16 variables:
## $ Subregion : chr "Gulf Islands" "Gulf Islands" "Saanich Peninsula" "Gulf Islands" ...
## $ Site : chr "Anniversary Island" "AVNR" "Bear Hill Park" "Brackman Island" ...
## $ Land_Manager : chr "GINPR" "Saltspring conservancy" "CRD" "GINPR" ...
## $ Main_Restoration_Type : chr "herbivore reduction" "herbivore reduction" "invasive removal" "invasive removal" ...
## $ Restoration_Intensity : Factor w/ 4 levels "high","moderate",..: 1 4 3 1 1 1 1 1 3 2 ...
## $ Area_ha : num 4.39 20.54 3.8 4.41 10.1 ...
## $ Lat : num 48.8 48.8 48.5 48.7 48.4 ...
## $ Lng : num -123 -123 -123 -123 -124 ...
## $ Proportion_of_native_species: num 0.94 0.55 0.62 0.77 0.61 0.66 0.75 0.53 0.32 0.64 ...
## $ Cultural_species_richness : num 2.71 1.3 1.86 2.8 2.43 1.07 3.6 0.8 1 4.4 ...
## $ Exotic_species : num 0.17 57.19 24.46 11.17 27.19 ...
## $ Trampling : num 5 4.7 7.57 5.4 7.71 1.64 12.2 16.6 10.4 6.2 ...
## $ Herbivory : num 1.14 36.5 9.5 0 4.71 ...
## $ Composite_Index : num 1.8 0.6 1 2 1.4 1 1.6 0.8 0.4 1.6 ...
## $ Year : int 2023 2023 2023 2023 2023 2023 2023 2023 2023 2023 ...
## $ Percentage_ns : num 94 55 62 77 61 66 75 53 32 64 ...
# step 2
geo_eccc_sites_2 <- geo_eccc_sites_2[order(geo_eccc_sites_2$Restoration_Intensity),]
site_restInt_exotic <- ggplot(geo_eccc_sites_2,
aes(x = Exotic_species, y = Restoration_Intensity, color = Site)) +
geom_point(shape = 18, size = 2) +
#geom_bar(stat="identity") +
theme_minimal() + #get rid of grey background and tick marks
theme(legend.position="none") + #remove legend legen won't stick to bottom with ggplotly
theme(axis.text.x = element_text(angle = 25, vjust = 1, hjust=1, size = 7)) +
labs(title='Plotting Site by Restoration_Intensity & Exotic Species',
subtitle='ECCC',
caption = "Chart by Wendy Anthony \n 2025-08-20")
site_restInt_exotic
# ggplotly(site_restInt_exotic)
# change ggplotly legend to bottom
# %>%
# plotly::layout(legend=list(x=0,
# xanchor='left',
# yanchor='bottom',
# orientation='h'))
Need to reorder Restoration_Intensity using forcats library from tidyverse https://r-graph-gallery.com/267-reorder-a-variable-in-ggplot2.html
names(geo_eccc_sites_1)
## [1] "Subregion" "Site"
## [3] "Land_Manager" "Main_Restoration_Type"
## [5] "Restoration_Intensity" "Area_ha"
## [7] "Lat" "Lng"
## [9] "Proportion_of_native_species" "Cultural_species_richness"
## [11] "Exotic_species" "Trampling"
## [13] "Herbivory" "Composite_Index"
## [15] "Year" "Percentage_ns"
# Reorder following a precise order
# https://stackoverflow.com/questions/18413756/re-ordering-factor-levels-in-data-frame
# mydf$task <- factor(mydf$task, levels = c("up", "down", "left", "right", "front", "back"))
#geo_eccc_sites_1$Restoration_Intensity <- factor(geo_eccc_sites_1$Restoration_Intensity, levels = #c("high", "moderate", "low", "minimal"))
str(geo_eccc_sites_1)
## 'data.frame': 24 obs. of 16 variables:
## $ Subregion : chr "Gulf Islands" "Gulf Islands" "Saanich Peninsula" "Gulf Islands" ...
## $ Site : chr "Anniversary Island" "AVNR" "Bear Hill Park" "Brackman Island" ...
## $ Land_Manager : chr "GINPR" "Saltspring conservancy" "CRD" "GINPR" ...
## $ Main_Restoration_Type : chr "herbivore reduction" "herbivore reduction" "invasive removal" "invasive removal" ...
## $ Restoration_Intensity : chr "high" "minimal" "low" "high" ...
## $ Area_ha : num 4.39 20.54 3.8 4.41 10.1 ...
## $ Lat : num 48.8 48.8 48.5 48.7 48.4 ...
## $ Lng : num -123 -123 -123 -123 -124 ...
## $ Proportion_of_native_species: num 0.94 0.55 0.62 0.77 0.61 0.66 0.75 0.53 0.32 0.64 ...
## $ Cultural_species_richness : num 2.71 1.3 1.86 2.8 2.43 1.07 3.6 0.8 1 4.4 ...
## $ Exotic_species : num 0.17 57.19 24.46 11.17 27.19 ...
## $ Trampling : num 5 4.7 7.57 5.4 7.71 1.64 12.2 16.6 10.4 6.2 ...
## $ Herbivory : num 1.14 36.5 9.5 0 4.71 ...
## $ Composite_Index : num 1.8 0.6 1 2 1.4 1 1.6 0.8 0.4 1.6 ...
## $ Year : int 2023 2023 2023 2023 2023 2023 2023 2023 2023 2023 ...
## $ Percentage_ns : num 94 55 62 77 61 66 75 53 32 64 ...
# change character to factor
# str(geo_eccc_sites_1)
# geo_eccc_sites_1$Restoration_Intensity <- as.factor(geo_eccc_sites_1$Restoration_Intensity)
# str(geo_eccc_sites_1)
# # change factor to character
# geo_eccc_sites_1 <- data.frame(lapply(geo_eccc_sites_1, as.character), stringsAsFactors=FALSE)
# str(geo_eccc_sites_1)
# Step 1
desired_levels <- c("high", "moderate", "low", "minimal")
# create new df to create desired levels
geo_eccc_sites_2 <- geo_eccc_sites_1
# this changes data type from character to factor
geo_eccc_sites_2$Restoration_Intensity <- factor(geo_eccc_sites_1$Restoration_Intensity, levels = desired_levels)
print(levels(geo_eccc_sites_2$Restoration_Intensity)) # New order of levels
## [1] "high" "moderate" "low" "minimal"
str(geo_eccc_sites_2)
## 'data.frame': 24 obs. of 16 variables:
## $ Subregion : chr "Gulf Islands" "Gulf Islands" "Saanich Peninsula" "Gulf Islands" ...
## $ Site : chr "Anniversary Island" "AVNR" "Bear Hill Park" "Brackman Island" ...
## $ Land_Manager : chr "GINPR" "Saltspring conservancy" "CRD" "GINPR" ...
## $ Main_Restoration_Type : chr "herbivore reduction" "herbivore reduction" "invasive removal" "invasive removal" ...
## $ Restoration_Intensity : Factor w/ 4 levels "high","moderate",..: 1 4 3 1 1 1 1 1 3 2 ...
## $ Area_ha : num 4.39 20.54 3.8 4.41 10.1 ...
## $ Lat : num 48.8 48.8 48.5 48.7 48.4 ...
## $ Lng : num -123 -123 -123 -123 -124 ...
## $ Proportion_of_native_species: num 0.94 0.55 0.62 0.77 0.61 0.66 0.75 0.53 0.32 0.64 ...
## $ Cultural_species_richness : num 2.71 1.3 1.86 2.8 2.43 1.07 3.6 0.8 1 4.4 ...
## $ Exotic_species : num 0.17 57.19 24.46 11.17 27.19 ...
## $ Trampling : num 5 4.7 7.57 5.4 7.71 1.64 12.2 16.6 10.4 6.2 ...
## $ Herbivory : num 1.14 36.5 9.5 0 4.71 ...
## $ Composite_Index : num 1.8 0.6 1 2 1.4 1 1.6 0.8 0.4 1.6 ...
## $ Year : int 2023 2023 2023 2023 2023 2023 2023 2023 2023 2023 ...
## $ Percentage_ns : num 94 55 62 77 61 66 75 53 32 64 ...
# step 2
geo_eccc_sites_2 <- geo_eccc_sites_2[order(geo_eccc_sites_2$Restoration_Intensity),]
# values in order now -- ?? how to change to reverse order
site_restInt <- ggplot(geo_eccc_sites_2,
aes(x = Site, y = reorder(Restoration_Intensity, desc(Restoration_Intensity)), color = Subregion)) +
# reorder y variable axis
# https://stackoverflow.com/questions/28391850/reverse-order-of-discrete-y-axis-in-ggplot2s
# y = Restoration_Intensity
geom_point(shape = 18, size = 2) +
#geom_bar(stat="identity") +
theme_minimal() + #get rid of grey background and tick marks
theme(legend.position="bottom") + #remove legend
theme(axis.text.x = element_text(angle = 25, vjust = 1, hjust=1, size = 7)) +
labs(title='Plotting Sites by Restoration Intensity',
subtitle='ECCC',
caption = "Chart by Wendy Anthony \n 2025-08-22", x = "Site", y = "Restoration Intensity")
site_restInt
ggplotly(site_restInt)
Need to reorder Restoration_Intensity using forcats library from tidyverse https://r-graph-gallery.com/267-reorder-a-variable-in-ggplot2.html
names(geo_eccc_sites_1)
## [1] "Subregion" "Site"
## [3] "Land_Manager" "Main_Restoration_Type"
## [5] "Restoration_Intensity" "Area_ha"
## [7] "Lat" "Lng"
## [9] "Proportion_of_native_species" "Cultural_species_richness"
## [11] "Exotic_species" "Trampling"
## [13] "Herbivory" "Composite_Index"
## [15] "Year" "Percentage_ns"
# Reorder following a precise order
# https://stackoverflow.com/questions/18413756/re-ordering-factor-levels-in-data-frame
# mydf$task <- factor(mydf$task, levels = c("up", "down", "left", "right", "front", "back"))
#geo_eccc_sites_1$Restoration_Intensity <- factor(geo_eccc_sites_1$Restoration_Intensity, levels = #c("high", "moderate", "low", "minimal"))
str(geo_eccc_sites_1)
## 'data.frame': 24 obs. of 16 variables:
## $ Subregion : chr "Gulf Islands" "Gulf Islands" "Saanich Peninsula" "Gulf Islands" ...
## $ Site : chr "Anniversary Island" "AVNR" "Bear Hill Park" "Brackman Island" ...
## $ Land_Manager : chr "GINPR" "Saltspring conservancy" "CRD" "GINPR" ...
## $ Main_Restoration_Type : chr "herbivore reduction" "herbivore reduction" "invasive removal" "invasive removal" ...
## $ Restoration_Intensity : chr "high" "minimal" "low" "high" ...
## $ Area_ha : num 4.39 20.54 3.8 4.41 10.1 ...
## $ Lat : num 48.8 48.8 48.5 48.7 48.4 ...
## $ Lng : num -123 -123 -123 -123 -124 ...
## $ Proportion_of_native_species: num 0.94 0.55 0.62 0.77 0.61 0.66 0.75 0.53 0.32 0.64 ...
## $ Cultural_species_richness : num 2.71 1.3 1.86 2.8 2.43 1.07 3.6 0.8 1 4.4 ...
## $ Exotic_species : num 0.17 57.19 24.46 11.17 27.19 ...
## $ Trampling : num 5 4.7 7.57 5.4 7.71 1.64 12.2 16.6 10.4 6.2 ...
## $ Herbivory : num 1.14 36.5 9.5 0 4.71 ...
## $ Composite_Index : num 1.8 0.6 1 2 1.4 1 1.6 0.8 0.4 1.6 ...
## $ Year : int 2023 2023 2023 2023 2023 2023 2023 2023 2023 2023 ...
## $ Percentage_ns : num 94 55 62 77 61 66 75 53 32 64 ...
# change character to factor
# str(geo_eccc_sites_1)
# geo_eccc_sites_1$Restoration_Intensity <- as.factor(geo_eccc_sites_1$Restoration_Intensity)
# str(geo_eccc_sites_1)
# # change factor to character
# geo_eccc_sites_1 <- data.frame(lapply(geo_eccc_sites_1, as.character), stringsAsFactors=FALSE)
# str(geo_eccc_sites_1)
# Step 1
desired_levels <- c("high", "moderate", "low", "minimal")
# create new df to create desired levels
geo_eccc_sites_2 <- geo_eccc_sites_1
# this changes data type from character to factor
geo_eccc_sites_2$Restoration_Intensity <- factor(geo_eccc_sites_1$Restoration_Intensity, levels = desired_levels)
print(levels(geo_eccc_sites_2$Restoration_Intensity)) # New order of levels
## [1] "high" "moderate" "low" "minimal"
str(geo_eccc_sites_2)
## 'data.frame': 24 obs. of 16 variables:
## $ Subregion : chr "Gulf Islands" "Gulf Islands" "Saanich Peninsula" "Gulf Islands" ...
## $ Site : chr "Anniversary Island" "AVNR" "Bear Hill Park" "Brackman Island" ...
## $ Land_Manager : chr "GINPR" "Saltspring conservancy" "CRD" "GINPR" ...
## $ Main_Restoration_Type : chr "herbivore reduction" "herbivore reduction" "invasive removal" "invasive removal" ...
## $ Restoration_Intensity : Factor w/ 4 levels "high","moderate",..: 1 4 3 1 1 1 1 1 3 2 ...
## $ Area_ha : num 4.39 20.54 3.8 4.41 10.1 ...
## $ Lat : num 48.8 48.8 48.5 48.7 48.4 ...
## $ Lng : num -123 -123 -123 -123 -124 ...
## $ Proportion_of_native_species: num 0.94 0.55 0.62 0.77 0.61 0.66 0.75 0.53 0.32 0.64 ...
## $ Cultural_species_richness : num 2.71 1.3 1.86 2.8 2.43 1.07 3.6 0.8 1 4.4 ...
## $ Exotic_species : num 0.17 57.19 24.46 11.17 27.19 ...
## $ Trampling : num 5 4.7 7.57 5.4 7.71 1.64 12.2 16.6 10.4 6.2 ...
## $ Herbivory : num 1.14 36.5 9.5 0 4.71 ...
## $ Composite_Index : num 1.8 0.6 1 2 1.4 1 1.6 0.8 0.4 1.6 ...
## $ Year : int 2023 2023 2023 2023 2023 2023 2023 2023 2023 2023 ...
## $ Percentage_ns : num 94 55 62 77 61 66 75 53 32 64 ...
# step 2
geo_eccc_sites_2 <- geo_eccc_sites_2[order(geo_eccc_sites_2$Restoration_Intensity),]
# values in order now -- ?? how to change to reverse order
site_restInt_x <- ggplot(geo_eccc_sites_2,
aes(x = reorder(Site,
desc(Restoration_Intensity)),
y = reorder(Restoration_Intensity, desc(Restoration_Intensity)), color = Subregion)) +
# reorder y variable axis
# https://stackoverflow.com/questions/28391850/reverse-order-of-discrete-y-axis-in-ggplot2s
# y = Restoration_Intensity
geom_point(shape = 18, size = 2) +
#geom_bar(stat="identity") +
theme_minimal() + #get rid of grey background and tick marks
theme(legend.position="bottom") + #remove legend
theme(axis.text.x = element_text(angle = 25, vjust = 1, hjust=1, size = 7)) +
labs(title='Plotting Site by Restoration_Intensity',
subtitle='ECCC',
caption = "Chart by Wendy Anthony \n 2025-08-26",
x = "Site", y = "Restoration_Intensity")
site_restInt_x
ggplotly(site_restInt_x)
Need to reorder Restoration_Intensity using forcats library from tidyverse https://r-graph-gallery.com/267-reorder-a-variable-in-ggplot2.html
names(geo_eccc_sites_1)
## [1] "Subregion" "Site"
## [3] "Land_Manager" "Main_Restoration_Type"
## [5] "Restoration_Intensity" "Area_ha"
## [7] "Lat" "Lng"
## [9] "Proportion_of_native_species" "Cultural_species_richness"
## [11] "Exotic_species" "Trampling"
## [13] "Herbivory" "Composite_Index"
## [15] "Year" "Percentage_ns"
# Reorder following a precise order
# https://stackoverflow.com/questions/18413756/re-ordering-factor-levels-in-data-frame
# mydf$task <- factor(mydf$task, levels = c("up", "down", "left", "right", "front", "back"))
#geo_eccc_sites_1$Restoration_Intensity <- factor(geo_eccc_sites_1$Restoration_Intensity, levels = #c("high", "moderate", "low", "minimal"))
str(geo_eccc_sites_1)
## 'data.frame': 24 obs. of 16 variables:
## $ Subregion : chr "Gulf Islands" "Gulf Islands" "Saanich Peninsula" "Gulf Islands" ...
## $ Site : chr "Anniversary Island" "AVNR" "Bear Hill Park" "Brackman Island" ...
## $ Land_Manager : chr "GINPR" "Saltspring conservancy" "CRD" "GINPR" ...
## $ Main_Restoration_Type : chr "herbivore reduction" "herbivore reduction" "invasive removal" "invasive removal" ...
## $ Restoration_Intensity : chr "high" "minimal" "low" "high" ...
## $ Area_ha : num 4.39 20.54 3.8 4.41 10.1 ...
## $ Lat : num 48.8 48.8 48.5 48.7 48.4 ...
## $ Lng : num -123 -123 -123 -123 -124 ...
## $ Proportion_of_native_species: num 0.94 0.55 0.62 0.77 0.61 0.66 0.75 0.53 0.32 0.64 ...
## $ Cultural_species_richness : num 2.71 1.3 1.86 2.8 2.43 1.07 3.6 0.8 1 4.4 ...
## $ Exotic_species : num 0.17 57.19 24.46 11.17 27.19 ...
## $ Trampling : num 5 4.7 7.57 5.4 7.71 1.64 12.2 16.6 10.4 6.2 ...
## $ Herbivory : num 1.14 36.5 9.5 0 4.71 ...
## $ Composite_Index : num 1.8 0.6 1 2 1.4 1 1.6 0.8 0.4 1.6 ...
## $ Year : int 2023 2023 2023 2023 2023 2023 2023 2023 2023 2023 ...
## $ Percentage_ns : num 94 55 62 77 61 66 75 53 32 64 ...
# change character to factor
# str(geo_eccc_sites_1)
# geo_eccc_sites_1$Restoration_Intensity <- as.factor(geo_eccc_sites_1$Restoration_Intensity)
# str(geo_eccc_sites_1)
# # change factor to character
# geo_eccc_sites_1 <- data.frame(lapply(geo_eccc_sites_1, as.character), stringsAsFactors=FALSE)
# str(geo_eccc_sites_1)
# Step 1
desired_levels <- c("high", "moderate", "low", "minimal")
# this changes data type from character to factor
geo_eccc_sites_2$Restoration_Intensity <- factor(geo_eccc_sites_1$Restoration_Intensity, levels = desired_levels)
print(levels(geo_eccc_sites_2$Restoration_Intensity)) # New order of levels
## [1] "high" "moderate" "low" "minimal"
str(geo_eccc_sites_2)
## 'data.frame': 24 obs. of 16 variables:
## $ Subregion : chr "Gulf Islands" "Gulf Islands" "Saanich Peninsula" "Gulf Islands" ...
## $ Site : chr "Anniversary Island" "Brackman Island" "Camas Hill" "Crows Nest" ...
## $ Land_Manager : chr "GINPR" "GINPR" "HAT" "Trinity Western University" ...
## $ Main_Restoration_Type : chr "herbivore reduction" "invasive removal" "invasive removal" "herbivore reduction" ...
## $ Restoration_Intensity : Factor w/ 4 levels "high","moderate",..: 1 4 3 1 1 1 1 1 3 2 ...
## $ Area_ha : num 4.39 4.41 10.1 15.34 0.54 ...
## $ Lat : num 48.8 48.7 48.4 48.8 48.7 ...
## $ Lng : num -123 -123 -124 -123 -123 ...
## $ Proportion_of_native_species: num 0.94 0.77 0.61 0.66 0.75 0.53 0.41 0.47 0.62 0.54 ...
## $ Cultural_species_richness : num 2.71 2.8 2.43 1.07 3.6 0.8 1.56 1.5 3.6 3.57 ...
## $ Exotic_species : num 0.17 11.17 27.19 31.51 8.8 ...
## $ Trampling : num 5 5.4 7.71 1.64 12.2 ...
## $ Herbivory : num 1.14 0 4.71 26.71 0.1 ...
## $ Composite_Index : num 1.8 2 1.4 1 1.6 0.8 0.4 1 1 1.6 ...
## $ Year : int 2023 2023 2023 2023 2023 2023 2023 2023 2023 2023 ...
## $ Percentage_ns : num 94 77 61 66 75 53 41 47 62 54 ...
# step 2
geo_eccc_sites_2 <- geo_eccc_sites_2[order(geo_eccc_sites_2$Restoration_Intensity),]
# values in order now -- ?? how to change to reverse order
site_restInt_bar <- ggplot(geo_eccc_sites_2,
aes(y = reorder(Restoration_Intensity, desc(Restoration_Intensity)), color = Site, fill = Site)) +
# reorder y variable axis
# https://stackoverflow.com/questions/28391850/reverse-order-of-discrete-y-axis-in-ggplot2s
# y = Restoration_Intensity
geom_bar() +
#geom_bar(stat="identity") +
theme_minimal() + #get rid of grey background and tick marks
theme(legend.position="bottom") + #remove legend
theme(axis.text.x = element_text(angle = 25, vjust = 1, hjust=1, size = 7)) +
labs(title='Plotting Site by Restoration_Intensity',
subtitle='ECCC',
caption = "Chart by Wendy Anthony \n 2025-08-26", y = "Restoration_Intensity")
site_restInt_bar
ggplotly(site_restInt_bar)
subregion_exsp <- ggplot(geo_eccc,
aes(x = Subregion, y = Exotic_species)) +
geom_violin(fill = "seagreen2") +
geom_boxplot(width = 0.1, fill = "sandybrown") +
theme_minimal() + #get rid of grey background and tick marks
theme(legend.position="none") + #remove legend
theme(axis.text.x = element_text(vjust = 1, size = 9)) +
labs(title='Plotting Subregion by Exotic_species',
subtitle='ECCC',
caption = "Chart by Wendy Anthony \n 2025-08-04")
subregion_exsp
# plotly won't work here
names(geo_eccc)
## [1] "Subregion" "Site"
## [3] "Proportion_of_native_species" "Cultural_species_richness"
## [5] "Exotic_species" "Trampling"
## [7] "Herbivory" "Composite_Index"
## [9] "Year" "Percentage_ns"
subregion_nsp <- ggplot(geo_eccc,
aes(x = Subregion, y = Percentage_ns)) +
geom_violin(fill = "seagreen2") +
geom_boxplot(width = 0.1, fill = "sandybrown") +
theme_minimal() + #get rid of grey background and tick marks
theme(legend.position="none") + #remove legend
theme(axis.text.x = element_text(vjust = 1, size = 9)) +
labs(title='Plotting Subregion by Percentage of Native Species',
subtitle='ECCC',
caption = "Chart by Wendy Anthony \n 2025-08-27")
subregion_nsp
# plotly won't work here
library(cowplot)
subregion_exsp_1 <- subregion_exsp + labs(title='Exotic Species',
subtitle='ECCC',
caption = "2025-08-27")
subregion_nsp_1 <- subregion_nsp + labs(title='Native Species',
subtitle='ECCC',
caption = "2025-08-27")
plot_grid(subregion_exsp_1, subregion_nsp_1, labels = "AUTO")
names(geo_eccc_sites_1)
## [1] "Subregion" "Site"
## [3] "Land_Manager" "Main_Restoration_Type"
## [5] "Restoration_Intensity" "Area_ha"
## [7] "Lat" "Lng"
## [9] "Proportion_of_native_species" "Cultural_species_richness"
## [11] "Exotic_species" "Trampling"
## [13] "Herbivory" "Composite_Index"
## [15] "Year" "Percentage_ns"
str(geo_eccc_sites_1)
## 'data.frame': 24 obs. of 16 variables:
## $ Subregion : chr "Gulf Islands" "Gulf Islands" "Saanich Peninsula" "Gulf Islands" ...
## $ Site : chr "Anniversary Island" "AVNR" "Bear Hill Park" "Brackman Island" ...
## $ Land_Manager : chr "GINPR" "Saltspring conservancy" "CRD" "GINPR" ...
## $ Main_Restoration_Type : chr "herbivore reduction" "herbivore reduction" "invasive removal" "invasive removal" ...
## $ Restoration_Intensity : chr "high" "minimal" "low" "high" ...
## $ Area_ha : num 4.39 20.54 3.8 4.41 10.1 ...
## $ Lat : num 48.8 48.8 48.5 48.7 48.4 ...
## $ Lng : num -123 -123 -123 -123 -124 ...
## $ Proportion_of_native_species: num 0.94 0.55 0.62 0.77 0.61 0.66 0.75 0.53 0.32 0.64 ...
## $ Cultural_species_richness : num 2.71 1.3 1.86 2.8 2.43 1.07 3.6 0.8 1 4.4 ...
## $ Exotic_species : num 0.17 57.19 24.46 11.17 27.19 ...
## $ Trampling : num 5 4.7 7.57 5.4 7.71 1.64 12.2 16.6 10.4 6.2 ...
## $ Herbivory : num 1.14 36.5 9.5 0 4.71 ...
## $ Composite_Index : num 1.8 0.6 1 2 1.4 1 1.6 0.8 0.4 1.6 ...
## $ Year : int 2023 2023 2023 2023 2023 2023 2023 2023 2023 2023 ...
## $ Percentage_ns : num 94 55 62 77 61 66 75 53 32 64 ...
subregion_restInt <- ggplot(geo_eccc_sites_1,
aes(y = Restoration_Intensity)) +
# geom_violin(fill = "seagreen2") +
geom_bar(width = 0.1, fill = "sandybrown") +
theme_minimal() + #get rid of grey background and tick marks
theme(legend.position="none") + #remove legend
theme(axis.text.x = element_text(angle = 25, vjust = 1, hjust=1, size = 7)) +
labs(title='Plotting Subregion by Restoration_Intensity',
subtitle='ECCC',
caption = "Chart by Wendy Anthony \n 2025-08-20")
subregion_restInt
ggplotly()
# plotly won't work here
subregion_natsp <- ggplot(geo_eccc_1,
aes(x = Subregion, y = Percentage_ns)) +
geom_violin(fill = "seagreen2") +
geom_boxplot(width = 0.1, fill = "sandybrown") +
theme_minimal() + #get rid of grey background and tick marks
theme(legend.position="none") + #remove legend
theme(axis.text.x = element_text(angle = 25, vjust = 1, hjust=1, size = 7)) +
labs(title='Plotting Subregion by Proportion_of_native_species',
subtitle='ECCC',
caption = "Chart by Wendy Anthony \n 2025-08-04")
subregion_natsp
colnames(geo_eccc_1)
## [1] "Subregion" "Site"
## [3] "Proportion_of_native_species" "Cultural_species_richness"
## [5] "Exotic_species" "Trampling"
## [7] "Herbivory" "Composite_Index"
## [9] "Year" "Percentage_ns"
# choose index row from data sorted alphabetically
# delete first 2 columns as they can't be characters ? also Proportion to leave Percentage
# delete year column
# Anniversary_Island
Anniversary_Island <- geo_eccc_1[1, ]
Anniversary_Island
## Subregion Site Proportion_of_native_species
## 1 Gulf Islands Anniversary Island 0.94
## Cultural_species_richness Exotic_species Trampling Herbivory Composite_Index
## 1 2.71 0.17 5 1.14 1.8
## Year Percentage_ns
## 1 2023 94
Anniversary_Island <- Anniversary_Island[, -c(1,2,9)]
Anniversary_Island_long <- Anniversary_Island %>% pivot_longer(everything(), names_to = "variable", values_to = "value")
Anniversary_Island_long
## # A tibble: 7 × 2
## variable value
## <chr> <dbl>
## 1 Proportion_of_native_species 0.94
## 2 Cultural_species_richness 2.71
## 3 Exotic_species 0.17
## 4 Trampling 5
## 5 Herbivory 1.14
## 6 Composite_Index 1.8
## 7 Percentage_ns 94
# Gonzales
Gonzales <- geo_eccc_1[15, ]
Gonzales
## Subregion Site Proportion_of_native_species
## 15 Gulf Islands Owl Islet 0.65
## Cultural_species_richness Exotic_species Trampling Herbivory Composite_Index
## 15 2 27.72 10.67 0.67 1.4
## Year Percentage_ns
## 15 2023 65
Gonzales <- Gonzales[, -c(1,2,9)]
Gonzales
## Proportion_of_native_species Cultural_species_richness Exotic_species
## 15 0.65 2 27.72
## Trampling Herbivory Composite_Index Percentage_ns
## 15 10.67 0.67 1.4 65
Gonzales_long <- Gonzales %>% pivot_longer(everything(), names_to = "variable", values_to = "value")
Gonzales_long
## # A tibble: 7 × 2
## variable value
## <chr> <dbl>
## 1 Proportion_of_native_species 0.65
## 2 Cultural_species_richness 2
## 3 Exotic_species 27.7
## 4 Trampling 10.7
## 5 Herbivory 0.67
## 6 Composite_Index 1.4
## 7 Percentage_ns 65
# Uplands
Uplands <- geo_eccc_1[24, ]
Uplands
## Subregion Site Proportion_of_native_species
## 24 Saanich Peninsula Uplands Park 0.37
## Cultural_species_richness Exotic_species Trampling Herbivory Composite_Index
## 24 1.45 49.38 2.36 5.82 1
## Year Percentage_ns
## 24 2023 37
Uplands <- Uplands[, -c(1,2,9)]
Uplands
## Proportion_of_native_species Cultural_species_richness Exotic_species
## 24 0.37 1.45 49.38
## Trampling Herbivory Composite_Index Percentage_ns
## 24 2.36 5.82 1 37
Uplands_long <- Uplands %>% pivot_longer(everything(), names_to = "variable", values_to = "value")
Uplands_long
## # A tibble: 7 × 2
## variable value
## <chr> <dbl>
## 1 Proportion_of_native_species 0.37
## 2 Cultural_species_richness 1.45
## 3 Exotic_species 49.4
## 4 Trampling 2.36
## 5 Herbivory 5.82
## 6 Composite_Index 1
## 7 Percentage_ns 37
Uplands_long_plot <- ggplot(Uplands_long,
aes(x = variable, y = value)) +
# https://www.sthda.com/english/wiki/ggplot2-axis-scales-and-transformations
ylim(0, 100) +
geom_point() +
theme_minimal() + #get rid of grey background and tick marks
theme(legend.position="none") + #remove legend
theme(axis.text.x = element_text(angle = 25, vjust = 1, hjust=1, size = 7)) +
labs(title='Plotting Uplands Variables',
subtitle='ECCC',
caption = "Chart by Wendy Anthony \n 2025-08-04")
Uplands_long_plot
Gonzales_long_plot <- ggplot(Gonzales_long,
aes(x = variable, y = value)) +
# https://www.sthda.com/english/wiki/ggplot2-axis-scales-and-transformations
ylim(0, 100) +
geom_point() +
theme_minimal() + #get rid of grey background and tick marks
theme(legend.position="none") + #remove legend
theme(axis.text.x = element_text(angle = 25, vjust = 1, hjust=1, size = 7)) +
labs(title='Plotting Gonzales Variables',
subtitle='ECCC',
caption = "Chart by Wendy Anthony \n 2025-08-04")
Gonzales_long_plot
Anniversary_Island_long_plot <- ggplot(Anniversary_Island_long,
aes(x = variable, y = value)) +
# https://www.sthda.com/english/wiki/ggplot2-axis-scales-and-transformations
ylim(0, 100) +
geom_point() +
theme_minimal() + #get rid of grey background and tick marks
theme(legend.position="none") + #remove legend
theme(axis.text.x = element_text(angle = 25, vjust = 1, hjust=1, size = 7)) +
labs(title='Plotting Anniversary Island Variables',
subtitle='ECCC',
caption = "Chart by Wendy Anthony \n 2025-08-04")
Anniversary_Island_long_plot
compare_bar_uplands <- ggplot(Uplands_long,
aes(x = variable, y = value)) +
# Exotic_species
# https://www.sthda.com/english/wiki/ggplot2-axis-scales-and-transformations
ylim(0, 100) +
geom_bar(stat = "identity", fill = "seagreen") +
theme_minimal() + #get rid of grey background and tick marks
theme(legend.position="none") + #remove legend
theme(axis.text.x = element_text(angle = 25, vjust = 1, hjust=1, size = 7)) +
labs(title='Comparinging Uplands Variables',
subtitle='ECCC',
caption = "Chart by Wendy Anthony \n 2025-08-08")
compare_bar_uplands
names(geo_eccc_1)
## [1] "Subregion" "Site"
## [3] "Proportion_of_native_species" "Cultural_species_richness"
## [5] "Exotic_species" "Trampling"
## [7] "Herbivory" "Composite_Index"
## [9] "Year" "Percentage_ns"
compare_bar_multiple_sites <- ggplot(geo_eccc_1,
aes(x = Site, y = Percentage_ns, fill = Subregion, color = Subregion)) +
# Exotic_species
# https://www.sthda.com/english/wiki/ggplot2-axis-scales-and-transformations
ylim(0, 100) +
geom_bar(stat = "identity") +
theme_minimal() + #get rid of grey background and tick marks
theme(legend.position="none") + #remove legend
theme(axis.text.x = element_text(angle = 25, vjust = 1, hjust=1, size = 7)) +
labs(title='Comparinging Uplands Variables',
subtitle='ECCC',
caption = "Chart by Wendy Anthony \n 2025-08-08")
compare_bar_multiple_sites
# https://r-graph-gallery.com/267-reorder-a-variable-in-ggplot2.html
names(geo_eccc_1)
## [1] "Subregion" "Site"
## [3] "Proportion_of_native_species" "Cultural_species_richness"
## [5] "Exotic_species" "Trampling"
## [7] "Herbivory" "Composite_Index"
## [9] "Year" "Percentage_ns"
# arrange values
#str(arr)
# geo_eccc_1 %>% arrange(Percentage_ns) -> arr
geo_eccc_1 %>% arrange(desc(Percentage_ns)) %>%
# updates Site with new arrangement
mutate(Site = factor(Site, levels = Site)) %>%
ggplot(
aes(x = Site, y = Percentage_ns, fill = Subregion, color = Subregion)) +
# https://www.sthda.com/english/wiki/ggplot2-axis-scales-and-transformations
ylim(0, 100) +
geom_bar(stat = "identity") +
theme_minimal() + #get rid of grey background and tick marks
theme(legend.position="bottom") +
theme(axis.text.x = element_text(angle = 35, vjust = 1, hjust=1, size = 7)) +
labs(title='Comparinging Sites',
subtitle='ECCC GOE Site Monitoring',
caption = "Chart by Wendy Anthony \n 2025-08-19")
# https://r-graph-gallery.com/267-reorder-a-variable-in-ggplot2.html
# View(mpg)
# g <- ggplot(geo_eccc_1, aes(Subregion))
# p <- g + geom_bar(aes(fill = Site))
# ggplotly(p)
#
# #https://stackoverflow.com/questions/6693257/making-a-stacked-bar-plot-for-multiple-variables-ggplot2-in-r
# dfr <- data.frame(
# V1 = c(0.1, 0.2, 0.3),
# V2 = c(0.2, 0.3, 0.2),
# V3 = c(0.3, 0.6, 0.5),
# V4 = c(0.5, 0.1, 0.7),
# row.names = LETTERS[1:3]
# )
#
# geo_eccc_2 <- subset(geo_eccc_1, , -c(Subregion))
#
# geo_eccc_2 %>% rownames_to_column("ID") %>% pivot_longer(!ID) %>%
# ggplot() +
# geom_col(aes(x = ID, y = value, fill = name), position = 'fill')
# # Error in `pivot_longer_spec()`:
# #! Can't combine `Site` <character> and `Proportion_of_native_species` <double>.
#
# names(geo_eccc_1)
# ggplot(geo_eccc_1,
# aes(x = Site, y = Percentage_ns, fill = Subregion, color = Subregion)) +
# # https://www.sthda.com/english/wiki/ggplot2-axis-scales-and-transformations
# ylim(0, 100) +
# geom_bar(stat = "identity") +
# theme_minimal() + #get rid of grey background and tick marks
# theme(legend.position="bottom") +
# theme(axis.text.x = element_text(angle = 35, vjust = 1, hjust=1, size = 7)) +
# labs(title='Comparinging Sites',
# subtitle='ECCC GOE Site Monitoring',
# caption = "Chart by Wendy Anthony \n 2025-08-19")
colnames(geo_eccc_1)
## [1] "Subregion" "Site"
## [3] "Proportion_of_native_species" "Cultural_species_richness"
## [5] "Exotic_species" "Trampling"
## [7] "Herbivory" "Composite_Index"
## [9] "Year" "Percentage_ns"
geo_eccc_1_filter <- filter(geo_eccc_1, geo_eccc_1$Site %in% c("Uplands Park", "Trial Island"))
compare_col_uplands <- ggplot(geo_eccc_1_filter,
aes(geo_eccc_1_filter$Site, fill = geo_eccc_1_filter$Exotic_species)) +
geom_bar(position = "dodge", alpha = 0.5) +
theme_minimal() + #get rid of grey background and tick marks
theme(legend.position="none") + #remove legend
theme(axis.text.x = element_text(angle = 25, vjust = 1, hjust=1, size = 7)) +
labs(title='Comparinging Uplands Variables',
subtitle='ECCC',
caption = "Chart by Wendy Anthony \n 2025-08-08")
compare_col_uplands
## Warning: Use of `geo_eccc_1_filter$Site` is discouraged.
## ℹ Use `Site` instead.
## Warning: Use of `geo_eccc_1_filter$Exotic_species` is discouraged.
## ℹ Use `Exotic_species` instead.
names(geo_eccc_1)
## [1] "Subregion" "Site"
## [3] "Proportion_of_native_species" "Cultural_species_richness"
## [5] "Exotic_species" "Trampling"
## [7] "Herbivory" "Composite_Index"
## [9] "Year" "Percentage_ns"
ggplot(geo_eccc_1,
aes(x = Site, y = Exotic_species)) +
geom_col() +
facet_wrap(~Subregion) +
theme(legend.position="none") + #remove legend
theme(axis.text.x = element_text(angle = 25, vjust = 1, hjust=1, size = 7)) +
labs(title='Comparinging Uplands Variables',
subtitle='ECCC',
caption = "Chart by Wendy Anthony \n 2025-08-19")
names(geo_eccc_1)
## [1] "Subregion" "Site"
## [3] "Proportion_of_native_species" "Cultural_species_richness"
## [5] "Exotic_species" "Trampling"
## [7] "Herbivory" "Composite_Index"
## [9] "Year" "Percentage_ns"
ggplot(geo_eccc_1,
aes(x = Site, y = Exotic_species)) +
geom_col() +
facet_wrap(~Subregion) +
theme(legend.position="none") + #remove legend
theme(axis.text.x = element_text(angle = 25, vjust = 1, hjust=1, size = 7)) +
labs(title='Comparinging Uplands Variables',
subtitle='ECCC',
caption = "Chart by Wendy Anthony \n 2025-08-19")
geo_eccc <- read.csv("SiteData-TEST-GOE-Monitor.csv", header = TRUE, sep = ",", stringsAsFactors=FALSE)
str(geo_eccc)
## 'data.frame': 24 obs. of 9 variables:
## $ Subregion : chr "Gulf Islands" "Gulf Islands" "Gulf Islands" "Gulf Islands" ...
## $ Site : chr "Anniversary Island" "AVNR" "Brackman Island" "Crows Nest" ...
## $ Proportion_of_native_species: num 0.94 0.55 0.77 0.66 0.75 0.53 0.45 0.65 0.62 0.58 ...
## $ Cultural_species_richness : num 2.71 1.3 2.8 1.07 3.6 0.8 0.42 2 3.6 2.33 ...
## $ Exotic_species : num 0.17 57.19 11.17 31.51 8.8 ...
## $ Trampling : num 5 4.7 5.4 1.64 12.2 ...
## $ Herbivory : num 1.14 36.5 0 26.71 0.1 ...
## $ Composite_Index : num 1.8 0.6 2 1 1.6 0.8 0.2 1.4 1 1 ...
## $ Year : int 2023 2023 2023 2023 2023 2023 2023 2023 2023 2023 ...
names(geo_eccc)
## [1] "Subregion" "Site"
## [3] "Proportion_of_native_species" "Cultural_species_richness"
## [5] "Exotic_species" "Trampling"
## [7] "Herbivory" "Composite_Index"
## [9] "Year"
subregion_var_violin <- function(file, title, subtitle, colx, coly, xlab, ylab, caption){
ggplot2::ggplot(file,
ggplot2::aes(x = colx, y = coly)) +
ggplot2::geom_violin(fill = "seagreen2") +
ggplot2::geom_boxplot(width = 0.1, fill = "sandybrown") +
ggplot2::theme_minimal() + #get rid of grey background and tick marks
ggplot2::theme(legend.position="none") + #remove legend
ggplot2::theme(
axis.text.x = ggplot2::element_text(vjust = 1, hjust = .5, size = 8),
axis.text.y = ggplot2::element_text(size = 5),
plot.title = ggplot2::element_text(hjust = 0.5, size = 12),
plot.subtitle = ggplot2::element_text(hjust = 0.5, size = 12)) +
#theme(axis.text.x = element_text(angle = 25, vjust = 1, hjust=1, size = 7)) +
ggplot2::labs(title=title,
subtitle=subtitle,
caption = caption,
x = xlab, y = ylab)
#subregion_exsp
}
subregion_var_violin(geo_eccc, 'Plotting Subregion by Exotic_species', 'ECCC Data Paper', geo_eccc$Subregion, geo_eccc$Exotic_species, "Subregion", "Exotic_species", "Chart by Wendy Anthony \n 2025-08-04")
subregion_var_violin(geo_eccc,'Plotting Subregion by Cultural_species_richness', 'ECCC Data Paper', geo_eccc$Subregion, geo_eccc$Cultural_species_richness, "Subregion", "Cultural_species_richness", "Chart by Wendy Anthony \n 2025-08-16")
geo_eccc <- read.csv("SiteData-TEST-GOE-Monitor.csv", header = TRUE, sep = ",", stringsAsFactors=FALSE)
str(geo_eccc)
## 'data.frame': 24 obs. of 9 variables:
## $ Subregion : chr "Gulf Islands" "Gulf Islands" "Gulf Islands" "Gulf Islands" ...
## $ Site : chr "Anniversary Island" "AVNR" "Brackman Island" "Crows Nest" ...
## $ Proportion_of_native_species: num 0.94 0.55 0.77 0.66 0.75 0.53 0.45 0.65 0.62 0.58 ...
## $ Cultural_species_richness : num 2.71 1.3 2.8 1.07 3.6 0.8 0.42 2 3.6 2.33 ...
## $ Exotic_species : num 0.17 57.19 11.17 31.51 8.8 ...
## $ Trampling : num 5 4.7 5.4 1.64 12.2 ...
## $ Herbivory : num 1.14 36.5 0 26.71 0.1 ...
## $ Composite_Index : num 1.8 0.6 2 1 1.6 0.8 0.2 1.4 1 1 ...
## $ Year : int 2023 2023 2023 2023 2023 2023 2023 2023 2023 2023 ...
names(geo_eccc)
## [1] "Subregion" "Site"
## [3] "Proportion_of_native_species" "Cultural_species_richness"
## [5] "Exotic_species" "Trampling"
## [7] "Herbivory" "Composite_Index"
## [9] "Year"
subregion_var_point <- function(file, title, subtitle, colx, coly, xlab, ylab, caption){
ggplot(file,
aes(x = colx, y = coly, colour = Subregion)) +
geom_point(shape = 18, size = 2) +
theme_minimal() + #get rid of grey background and tick marks
theme(legend.position="bottom") +
# theme(legend.position="none") + #remove legend
theme(axis.text.x = element_text(angle =35, vjust = 1, hjust=1, size = 7)) +
labs(title=title,
subtitle=subtitle,
caption = caption,
x = xlab, y = ylab)
}
subregion_var_point(geo_eccc,'Plotting Site by Percentage Native Species', 'Malloff & Shackelford. (2024). \nFeeling the Pulse: Monitoring methods and initial outcomes in oak meadow ecosystems. \nRestoration Futures Lab at the University of Victoria.
', geo_eccc$Site, geo_eccc$Proportion_of_native_species, "Site", "Proportion of native species", "Chart by Wendy Anthony \n 2025-09-16 \n ECCC Data: (Malloff & Shackelford, 2024)")
subregion_var_point(geo_eccc,'Plotting Site by Exotic Species', 'Malloff & Shackelford. (2024). \nFeeling the Pulse: Monitoring methods and initial outcomes in oak meadow ecosystems. \nRestoration Futures Lab at the University of Victoria.
', geo_eccc$Site, geo_eccc$Exotic_species, "Site", "Exotic Species", "Chart by Wendy Anthony \n 2025-09-16 \n ECCC Data: (Malloff & Shackelford, 2024)")
geo_eccc <- read.csv("SiteData-TEST-GOE-Monitor.csv", header = TRUE, sep = ",", stringsAsFactors=FALSE)
str(geo_eccc)
## 'data.frame': 24 obs. of 9 variables:
## $ Subregion : chr "Gulf Islands" "Gulf Islands" "Gulf Islands" "Gulf Islands" ...
## $ Site : chr "Anniversary Island" "AVNR" "Brackman Island" "Crows Nest" ...
## $ Proportion_of_native_species: num 0.94 0.55 0.77 0.66 0.75 0.53 0.45 0.65 0.62 0.58 ...
## $ Cultural_species_richness : num 2.71 1.3 2.8 1.07 3.6 0.8 0.42 2 3.6 2.33 ...
## $ Exotic_species : num 0.17 57.19 11.17 31.51 8.8 ...
## $ Trampling : num 5 4.7 5.4 1.64 12.2 ...
## $ Herbivory : num 1.14 36.5 0 26.71 0.1 ...
## $ Composite_Index : num 1.8 0.6 2 1 1.6 0.8 0.2 1.4 1 1 ...
## $ Year : int 2023 2023 2023 2023 2023 2023 2023 2023 2023 2023 ...
names(geo_eccc)
## [1] "Subregion" "Site"
## [3] "Proportion_of_native_species" "Cultural_species_richness"
## [5] "Exotic_species" "Trampling"
## [7] "Herbivory" "Composite_Index"
## [9] "Year"
subregion_var_point <- function(file, title, subtitle, colx, coly, xlab, ylab, caption){
ggplot(file,
aes(x = colx, y = coly, colour = Subregion)) +
geom_point(shape = 18, size = 2) +
theme_minimal() + #get rid of grey background and tick marks
theme(legend.position="bottom") +
# theme(legend.position="none") + #remove legend
theme(axis.text.x = element_text(angle =35, vjust = 1, hjust=1, size = 7)) +
labs(title=title,
subtitle=subtitle,
caption = caption,
x = xlab, y = ylab)
}
p2 <- subregion_var_point(geo_eccc,'Plotting Site by Percentage Native Species', 'Malloff & Shackelford. (2024). \nFeeling the Pulse: Monitoring methods and initial outcomes in oak meadow ecosystems. \nRestoration Futures Lab at the University of Victoria.
', geo_eccc$Site, geo_eccc$Proportion_of_native_species, "Site", "Proportion of native species", "Chart by Wendy Anthony \n 2025-09-16 \n ECCC Data: (Malloff & Shackelford, 2024)")
subregion_var_point(geo_eccc,'Plotting Site by Exotic Species', 'Malloff & Shackelford. (2024). \nFeeling the Pulse: Monitoring methods and initial outcomes in oak meadow ecosystems. \nRestoration Futures Lab at the University of Victoria.
', geo_eccc$Site, geo_eccc$Exotic_species, "Site", "Exotic Species", "Chart by Wendy Anthony \n 2025-09-16 \n ECCC Data: (Malloff & Shackelford, 2024)")
ggplotly(p2)
Sites_eccc <- read.csv("SiteDetails-TEST-GOE-Monitor.csv", header = TRUE, sep = ",")
names(Sites_eccc)
## [1] "Subregion" "Site" "Land.Manager"
## [4] "Main.Restoration.Type" "Restoration.Intensity" "Area.ha"
## [7] "Lat" "Lng"
library(dplyr)
library(leaflet)
library(htmlwidgets) # for responsive web map
# custom icon
# https://leafletjs.com/examples/custom-icons/
greenLeafIcon <- makeIcon(
iconUrl = "https://leafletjs.com/examples/custom-icons/leaf-green.png",
iconWidth = 38, iconHeight = 95,
iconAnchorX = 22, iconAnchorY = 94,
shadowUrl = "https://leafletjs.com/examples/custom-icons/leaf-shadow.png",
shadowWidth = 50, shadowHeight = 64,
shadowAnchorX = 4, shadowAnchorY = 62
)
# change LeafIcon size 1/2
greenLeafIconSm <- makeIcon(
iconUrl = "https://leafletjs.com/examples/custom-icons/leaf-green.png",
iconWidth = 19, iconHeight = 47,
iconAnchorX = 11, iconAnchorY = 47,
shadowUrl = "https://leafletjs.com/examples/custom-icons/leaf-shadow.png",
shadowWidth = 25, shadowHeight = 32,
shadowAnchorX = 2, shadowAnchorY = 31
)
# Title control
title <- tags$div(HTML('<b>ECC Site Maps</b><br>Malloff & Shackelford. (2024). Feeling the Pulse: Monitoring methods and initial outcomes in oak meadow ecosystems. Restoration Futures Lab at the University of Victoria'))
ECCC_map <- leaflet(Sites_eccc) %>%
addProviderTiles("Esri.WorldImagery") %>%
addMarkers(
~ Lng, ~ Lat, icon = greenLeafIconSm,
popup = paste0("<b>Subregion:</b> ", Sites_eccc$Subregion, "<br>", "<b>Site:</b> ", Sites_eccc$Site, "<br>", "<b>Latitude:</b> ", Sites_eccc$Lat, "<br>", "<b>Longitude:</b> ", Sites_eccc$Lng, "<br><br>", "<b>Land Manager:</b> ", Sites_eccc$Land.Manager, "<br>", "<b>Main Restoration:</b> ", Sites_eccc$Main.Restoration.Type, "<br>", "<b>Restoration Intensity:</b> ", Sites_eccc$Restoration.Intensity, "<br>", "<b> Area:</b> ", Sites_eccc$Area.ha, " ha")) %>%
setView(-123.44799, 48.64919, 9) %>%
addMiniMap(width = 150, height = 150, zoomLevelOffset = -4) %>%
addControl(title, position = "topright")
# Display map
ECCC_map
# Save map
saveWidget(ECCC_map, "ECCC_map.html")
# NOT WORKING - Sites not same
#geo_eccc_sites <- cbind(geo_eccc, Sites_eccc)
# try to add , "<br>", "<b>Composite Index:</b> ", geo_eccc_sites$Composite_Index
# names(geo_eccc_sites)
names(Sites_eccc)
## [1] "Subregion" "Site" "Land.Manager"
## [4] "Main.Restoration.Type" "Restoration.Intensity" "Area.ha"
## [7] "Lat" "Lng"
library(dplyr)
library(leaflet)
library(htmlwidgets) # for responsive web map
# Title control
title <- tags$div(HTML('<b>ECC Site Maps</b><br>Malloff & Shackelford. (2024). Feeling the Pulse: Monitoring methods and initial outcomes in oak meadow ecosystems. Restoration Futures Lab at the University of Victoria'))
# https://rstudio.github.io/leaflet/articles/markers.html
# Create a palette that maps factor levels to colors
pal <- colorFactor(c("green", "orange"), domain = c("Saanich Peninsula", "Gulf Islands"))
ECCC_map <- leaflet(Sites_eccc) %>%
addProviderTiles("Esri.WorldImagery") %>%
addCircleMarkers(
~ Lng, ~ Lat, radius = ~ifelse(Subregion == "Saanich Peninsula", 4, 5),
color = ~pal(Subregion),
stroke = FALSE, fillOpacity = 0.5,
popup = paste0("<b>Site:</b> ", Sites_eccc$Site, "<br>", "<b>Subregion:</b> ", Sites_eccc$Subregion, "<br>", "<b>Latitude:</b> ", Sites_eccc$Lat, "<br>", "<b>Longitude:</b> ", Sites_eccc$Lng, "<br><br>", "<b>Land Manager:</b> ", Sites_eccc$Land.Manager, "<br>", "<b>Main Restoration:</b> ", Sites_eccc$Main.Restoration.Type, "<br>", "<b>Restoration Intensity:</b> ", Sites_eccc$Restoration.Intensity, "<br>", "<b> Area:</b> ", Sites_eccc$Area.ha, " ha")) %>%
setView(-123.44799, 48.64919, 9) %>%
addMiniMap(width = 150, height = 150, zoomLevelOffset = -4) %>%
addControl(title, position = "topright")
# Display map
ECCC_map
# Save map
saveWidget(ECCC_map, "ECCC_map.html")
names(Sites_eccc)
## [1] "Subregion" "Site" "Land.Manager"
## [4] "Main.Restoration.Type" "Restoration.Intensity" "Area.ha"
## [7] "Lat" "Lng"
library(dplyr)
library(leaflet)
library(htmlwidgets) # for responsive web map
# Title control
# Malloff & Shackelford. (2024). Feeling the Pulse: Monitoring methods and initial outcomes in oak meadow ecosystems. Restoration Futures Lab at the University of Victoria
title <- tags$div(HTML('<p style="font-size:12px;font-weight:bold">ECC Sites Map</p>'))
# https://rstudio.github.io/leaflet/articles/markers.html
# Create a palette that maps factor levels to colors
pal <- colorFactor(c("green", "orange"), domain = c("Saanich Peninsula", "Gulf Islands"))
ECCC_map <- leaflet(Sites_eccc) %>%
addProviderTiles("Esri.WorldImagery") %>%
addCircleMarkers(
~ Lng, ~ Lat,
# https://stackoverflow.com/questions/40137212/variable-marker-size-feature-in-leaflet-r
radius = ~geo_eccc$Composite_Index * 3,
# radius = ~Sites_eccc$Area.ha,
# radius = ~sqrt(Sites_eccc$Area.ha),
# size smaller is Saanich, else larger if Gulf
# radius = ~ifelse(Subregion == "Saanich Peninsula", 4, 5),
color = ~pal(Subregion),
stroke = FALSE, fillOpacity = 0.5,
popup = paste0("<b>Site:</b> ", Sites_eccc$Site, "<br>", "<b>Subregion:</b> ", Sites_eccc$Subregion, "<br>", "<b>Latitude:</b> ", Sites_eccc$Lat, "<br>", "<b>Longitude:</b> ", Sites_eccc$Lng, "<br><br>", "<b>Land Manager:</b> ", Sites_eccc$Land.Manager, "<br>", "<b>Main Restoration:</b> ", Sites_eccc$Main.Restoration.Type, "<br>", "<b>Restoration Intensity:</b> ", Sites_eccc$Restoration.Intensity, "<br>", "<b> Area:</b> ", Sites_eccc$Area.ha, " ha")) %>%
setView(-123.44799, 48.64919, 9) %>%
addMiniMap(width = 150, height = 150, zoomLevelOffset = -4) %>%
addControl(title, position = "topright")
# Display map
ECCC_map
# Save map
saveWidget(ECCC_map, "ECCC_map.html")
geo_eccc_all_site_data.csv
geo_eccc_sites_1 <- read.csv("geo_eccc_all_site_data.csv")
names(geo_eccc_sites_1)
## [1] "Subregion" "Site"
## [3] "Land_Manager" "Main_Restoration_Type"
## [5] "Restoration_Intensity" "Area_ha"
## [7] "Lat" "Lng"
## [9] "Proportion_of_native_species" "Cultural_species_richness"
## [11] "Exotic_species" "Trampling"
## [13] "Herbivory" "Composite_Index"
## [15] "Year" "Percentage_ns"
library(dplyr)
library(leaflet)
library(htmlwidgets) # for responsive web map
# Title control
# Malloff & Shackelford. (2024). Feeling the Pulse: Monitoring methods and initial outcomes in oak meadow ecosystems. Restoration Futures Lab at the University of Victoria
title <- tags$div(HTML('<p style="font-size:12px;font-weight:bold">ECC Sites Map</p>'))
# https://rstudio.github.io/leaflet/articles/markers.html
# Create a palette that maps factor levels to colors
pal <- colorFactor(c("#d7191c", "#2c7bb6"), domain = c("Saanich Peninsula", "Gulf Islands"))
ECCC_map_1 <- leaflet(geo_eccc_sites_1) %>%
addProviderTiles("Esri.WorldImagery") %>%
addCircleMarkers(
~ Lng, ~ Lat,
# https://stackoverflow.com/questions/40137212/variable-marker-size-feature-in-leaflet-r
radius = ~geo_eccc_sites_1$Composite_Index * 5,
# radius = ~geo_eccc_sites_1$Area.ha,
# radius = ~sqrt(geo_eccc_sites_1$Area.ha),
# size smaller is Saanich, else larger if Gulf
# radius = ~ifelse(Subregion == "Saanich Peninsula", 4, 5),
fillColor = ~pal(Subregion),
color = "black",
weight = 3, # size of circle border
stroke = TRUE, fillOpacity = 0.5,
popup = paste0("<b>Site:</b> ", "<b>", "<b>", geo_eccc_sites_1$Site, "</b>", "</b>", "<br><br>", "<b>Subregion:</b> ", geo_eccc_sites_1$Subregion, "<br>",
"<b>Latitude:</b> ", geo_eccc_sites_1$Lat, "<br>", "<b>Longitude:</b> ", geo_eccc_sites_1$Lng, "<br><br>",
"<b>Land Manager:</b> ", geo_eccc_sites_1$Land_Manager, "<br>",
"<b>Main Restoration:</b> ", geo_eccc_sites_1$Main_Restoration_Type, "<br>",
"<b>Restoration Intensity:</b> ", geo_eccc_sites_1$Restoration_Intensity, "<br>",
"<b> Area:</b> ", geo_eccc_sites_1$Area_ha, " ha",
"<br><br>",
"<b>Proportion of native species:</b> ", geo_eccc_sites_1$Proportion_of_native_species, "<br>",
"<b>Cultural species richness:</b> ", geo_eccc_sites_1$Cultural_species_richness, "<br>",
"<b>Exotic species:</b> ", geo_eccc_sites_1$Exotic_species, "<br>",
"<b>Trampling:</b> ", geo_eccc_sites_1$Trampling, "<br>",
"<b>Herbivory:</b> ", geo_eccc_sites_1$Herbivory, "<br>",
"<b>Composite Index:</b> ", geo_eccc_sites_1$Composite_Index, "<br>")) %>%
setView(-123.44799, 48.64919, 10) %>%
addMiniMap(width = 150, height = 150, zoomLevelOffset = -4) %>%
addControl(title, position = "topright")
# Display map
ECCC_map_1
# Save map
saveWidget(ECCC_map_1, "ECCC_map_CI.html")
geo_eccc_all_site_data.csv
geo_eccc_sites_1 <- read.csv("geo_eccc_all_site_data.csv")
names(geo_eccc_sites_1)
## [1] "Subregion" "Site"
## [3] "Land_Manager" "Main_Restoration_Type"
## [5] "Restoration_Intensity" "Area_ha"
## [7] "Lat" "Lng"
## [9] "Proportion_of_native_species" "Cultural_species_richness"
## [11] "Exotic_species" "Trampling"
## [13] "Herbivory" "Composite_Index"
## [15] "Year" "Percentage_ns"
library(dplyr)
library(leaflet)
library(htmlwidgets) # for responsive web map
# Title control
# Malloff & Shackelford. (2024). Feeling the Pulse: Monitoring methods and initial outcomes in oak meadow ecosystems. Restoration Futures Lab at the University of Victoria
title <- '<p style="text-align: center; height: 30px; ">
<span style="font-size:10px;font-weight:bold; background-color: rgba(255, 255, 255, 0.9;");>ECCC GOE 2023 Monitoring Sites</span><br>
<span style="font-size:8px;font-style:italic; background-color: rgba(255, 255, 255, 0.9;">(Malloff & Shackelford, 2024)</span></p>'
# https://rstudio.github.io/leaflet/articles/markers.html
# Create a palette that maps factor levels to colors
pal <- colorFactor(c("#d7191c", "#2c7bb6"), domain = c("Saanich Peninsula", "Gulf Islands"))
ECCC_map_2 <- leaflet(geo_eccc_sites_1) %>%
addProviderTiles("Esri.WorldImagery") %>%
addCircleMarkers(
~ Lng, ~ Lat,
# https://stackoverflow.com/questions/40137212/variable-marker-size-feature-in-leaflet-r
# radius = ~geo_eccc_sites_1$Composite_Index * 5,
# radius = ~geo_eccc_sites_1$Area.ha,
# radius = ~sqrt(geo_eccc_sites_1$Area.ha),
# size smaller is Saanich, else larger if Gulf
radius = ~ifelse(Subregion == "Saanich Peninsula", 8, 8),
fillColor = ~pal(Subregion),
color = "black",
weight = 3, # size of circle border
stroke = TRUE, fillOpacity = 0.5,
popup = paste0("<b>ECCC GOE 2023 Monitoring Data</b>", "<br>", "<i>(Malloff & Shackelford, 2024)</i>", "<br><br>",
"<b>Site:</b> ", "<b>", geo_eccc_sites_1$Site, "</b>", "</b>", "<br><br>", "<b>Subregion:</b> ", geo_eccc_sites_1$Subregion, "<br>",
"<b>Latitude:</b> ", geo_eccc_sites_1$Lat, "<br>", "<b>Longitude:</b> ", geo_eccc_sites_1$Lng, "<br><br>",
"<b>Land Manager:</b> ", geo_eccc_sites_1$Land_Manager, "<br>",
"<b>Main Restoration:</b> ", geo_eccc_sites_1$Main_Restoration_Type, "<br>",
"<b>Restoration Intensity:</b> ", geo_eccc_sites_1$Restoration_Intensity, "<br>",
"<b> Area:</b> ", geo_eccc_sites_1$Area_ha, " ha",
"<br><br>",
"<b>Proportion of native species:</b> ", geo_eccc_sites_1$Proportion_of_native_species, "<br>",
"<b>Cultural species richness:</b> ", geo_eccc_sites_1$Cultural_species_richness, "<br>",
"<b>Exotic species:</b> ", geo_eccc_sites_1$Exotic_species, "<br>",
"<b>Trampling:</b> ", geo_eccc_sites_1$Trampling, "<br>",
"<b>Herbivory:</b> ", geo_eccc_sites_1$Herbivory, "<br>",
"<b>Composite Index:</b> ", geo_eccc_sites_1$Composite_Index, "<br>")) %>%
setView(-123.44799, 48.64919, 10) %>%
# add controls
addMiniMap(width = 150, height = 150, zoomLevelOffset = -4) %>%
addControl(title, position = "topright")
# Display map
ECCC_map_2
# Save map
saveWidget(ECCC_map_2, "ECCC_map_radius-1.html")
# colnames(geo_eccc_1)
library(shiny)
library(miniUI)
library(ggplot2)
lmGadget <- function(data, xvar, yvar) {
ui <- miniPage(
gadgetTitleBar("Interactive lm"),
miniContentPanel(
fillRow(flex = c(NA, 1),
fillCol(width = "100px",
selectInput("degree", "Polynomial degree", c(1, 2, 3, 4))
),
plotOutput("plot1",
height = "100%",
click = "plot1_click",
brush = brushOpts(
id = "plot1_brush"
)
)
)
),
miniButtonBlock(
actionButton("exclude_toggle", "Toggle points"),
actionButton("exclude_reset", "Reset")
)
)
server <- function(input, output) {
# For storing which rows have been excluded
vals <- reactiveValues(
keeprows = rep(TRUE, nrow(data))
)
output$plot1 <- renderPlot({
req(input$degree)
formula <- as.formula(paste0("y ~ poly(x, degree = ", input$degree, ")"))
# Plot the kept and excluded points as two separate data sets
keep <- data[ vals$keeprows, , drop = FALSE]
exclude <- data[!vals$keeprows, , drop = FALSE]
ggplot(keep, aes_string(xvar, yvar)) + geom_point() +
geom_smooth(method = lm, formula = formula, fullrange = TRUE, color = "gray50") +
geom_point(data = exclude, fill = NA, color = "black", alpha = 0.25) +
coord_cartesian(xlim = range(data[[xvar]]), ylim = range(data[[yvar]])) +
theme_bw(base_size = 14)
})
# Toggle points that are clicked
observeEvent(input$plot1_click, {
res <- nearPoints(data, input$plot1_click, allRows = TRUE)
vals$keeprows <- xor(vals$keeprows, res$selected_)
})
# Toggle points that are brushed, when button is clicked
observeEvent(input$exclude_toggle, {
res <- brushedPoints(data, input$plot1_brush, allRows = TRUE)
vals$keeprows <- xor(vals$keeprows, res$selected_)
})
# Reset all points
observeEvent(input$exclude_reset, {
vals$keeprows <- rep(TRUE, nrow(data))
})
# Handle the Done button being pressed.
observeEvent(input$done, {
# Replace x and y in the formula with the values in xvar and yvar
formula <- as.formula(paste0(yvar, " ~ poly(", xvar, ", degree = ", input$degree, ")"))
keep_data <- data[vals$keeprows, , drop = FALSE]
# Return the kept points.
stopApp(
list(
data = keep_data,
model = lm(formula, keep_data)
)
)
})
}
runGadget(ui, server, viewer = dialogViewer("lmGadget")) # separate viewer window
}
lmGadget(geo_eccc_1, "Percentage_ns", "Composite_Index")
lmGadget(iris, "Sepal.Length", "Sepal.Width")
## [1] "Subregion" "Site"
## [3] "Proportion_of_native_species" "Cultural_species_richness"
## [5] "Exotic_species" "Trampling"
## [7] "Herbivory" "Composite_Index"
## [9] "Year"
## 'data.frame': 24 obs. of 9 variables:
## $ Subregion : chr "Gulf Islands" "Gulf Islands" "Gulf Islands" "Gulf Islands" ...
## $ Site : chr "Anniversary Island" "AVNR" "Brackman Island" "Crows Nest" ...
## $ Proportion_of_native_species: num 0.94 0.55 0.77 0.66 0.75 0.53 0.45 0.65 0.62 0.58 ...
## $ Cultural_species_richness : num 2.71 1.3 2.8 1.07 3.6 0.8 0.42 2 3.6 2.33 ...
## $ Exotic_species : num 0.17 57.19 11.17 31.51 8.8 ...
## $ Trampling : num 5 4.7 5.4 1.64 12.2 ...
## $ Herbivory : num 1.14 36.5 0 26.71 0.1 ...
## $ Composite_Index : num 1.8 0.6 2 1 1.6 0.8 0.2 1.4 1 1 ...
## $ Year : int 2023 2023 2023 2023 2023 2023 2023 2023 2023 2023 ...
##
## Listening on http://127.0.0.1:7178
app-leaflet-reactive-AllSiteDetails-WORKING
##
## Attaching package: 'bslib'
## The following object is masked from 'package:utils':
##
## page
## [1] "Subregion" "Site"
## [3] "Land_Manager" "Main_Restoration_Type"
## [5] "Restoration_Intensity" "Area_ha"
## [7] "Lat" "Lng"
## [9] "Proportion_of_native_species" "Cultural_species_richness"
## [11] "Exotic_species" "Trampling"
## [13] "Herbivory" "Composite_Index"
## [15] "Year" "Percentage_ns"
## 'data.frame': 24 obs. of 16 variables:
## $ Subregion : chr "Gulf Islands" "Gulf Islands" "Saanich Peninsula" "Gulf Islands" ...
## $ Site : chr "Anniversary Island" "AVNR" "Bear Hill Park" "Brackman Island" ...
## $ Land_Manager : chr "GINPR" "Saltspring conservancy" "CRD" "GINPR" ...
## $ Main_Restoration_Type : chr "herbivore reduction" "herbivore reduction" "invasive removal" "invasive removal" ...
## $ Restoration_Intensity : chr "high" "minimal" "low" "high" ...
## $ Area_ha : num 4.39 20.54 3.8 4.41 10.1 ...
## $ Lat : num 48.8 48.8 48.5 48.7 48.4 ...
## $ Lng : num -123 -123 -123 -123 -124 ...
## $ Proportion_of_native_species: num 0.94 0.55 0.62 0.77 0.61 0.66 0.75 0.53 0.32 0.64 ...
## $ Cultural_species_richness : num 2.71 1.3 1.86 2.8 2.43 1.07 3.6 0.8 1 4.4 ...
## $ Exotic_species : num 0.17 57.19 24.46 11.17 27.19 ...
## $ Trampling : num 5 4.7 7.57 5.4 7.71 1.64 12.2 16.6 10.4 6.2 ...
## $ Herbivory : num 1.14 36.5 9.5 0 4.71 ...
## $ Composite_Index : num 1.8 0.6 1 2 1.4 1 1.6 0.8 0.4 1.6 ...
## $ Year : int 2023 2023 2023 2023 2023 2023 2023 2023 2023 2023 ...
## $ Percentage_ns : int 94 55 62 77 61 66 75 53 32 64 ...
##
## Listening on http://127.0.0.1:4957
app-datatable-search-plot-update-ECCC-TEST
https://stackoverflow.com/questions/52880657/in-an-shiny-app-i-want-a-plot-to-update-based-on-the-search-results-in-a-datat
##
## Attaching package: 'DT'
## The following objects are masked from 'package:shiny':
##
## dataTableOutput, renderDataTable
##
## Listening on http://127.0.0.1:8097
### Plot Select Axis Variables app4-SelectAxisVariables-WORKS.R
- this shiny app won’t knit - looses connection ???
##
## Attaching package: 'shinyscreenshot'
## The following object is masked from 'package:shiny':
##
## runExample
##
## Listening on http://127.0.0.1:5929
## [1] "Exotic_species"
## Warning in file(file, "rt"): cannot open file 'TEST-GOE-Monitor.csv': No such
## file or directory
## Warning: Error in file: cannot open the connection
## [1] "Proportion_of_native_species"
## Warning in file(file, "rt"): cannot open file 'TEST-GOE-Monitor.csv': No such
## file or directory
## Warning in file(file, "rt"): Error in file: cannot open the connection
# to document specific packages used to run script
sessionInfo()
## R version 4.2.1 (2022-06-23)
## Platform: x86_64-apple-darwin17.0 (64-bit)
## Running under: macOS Mojave 10.14.6
##
## Matrix products: default
## BLAS: /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRblas.0.dylib
## LAPACK: /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRlapack.dylib
##
## locale:
## [1] en_CA.UTF-8/en_CA.UTF-8/en_CA.UTF-8/C/en_CA.UTF-8/en_CA.UTF-8
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] shinyscreenshot_0.2.0 DT_0.26 bslib_0.4.0
## [4] htmlwidgets_1.5.4 leaflet_2.1.1 cowplot_1.1.1
## [7] plotly_4.10.1 forcats_0.5.2 stringr_1.4.1
## [10] dplyr_1.0.10 purrr_0.3.5 readr_2.1.3
## [13] tidyr_1.2.1 tibble_3.1.8 ggplot2_3.4.0
## [16] tidyverse_1.3.2 shiny_1.7.3
##
## loaded via a namespace (and not attached):
## [1] fs_1.5.2 fontawesome_0.4.0 lubridate_1.8.0
## [4] webshot_0.5.4 httr_1.4.4 tools_4.2.1
## [7] backports_1.4.1 utf8_1.2.2 R6_2.5.1
## [10] DBI_1.1.3 lazyeval_0.2.2 colorspace_2.0-3
## [13] withr_2.5.0 tidyselect_1.2.0 processx_3.7.0
## [16] compiler_4.2.1 textshaping_0.3.6 cli_3.4.1
## [19] rvest_1.0.3 xml2_1.3.3 labeling_0.4.2
## [22] sass_0.4.2 scales_1.2.1 callr_3.7.2
## [25] systemfonts_1.0.4 digest_0.6.30 rmarkdown_2.17
## [28] pkgconfig_2.0.3 htmltools_0.5.3 dbplyr_2.2.1
## [31] fastmap_1.1.0 highr_0.9 rlang_1.0.6
## [34] readxl_1.4.1 rstudioapi_0.14 jquerylib_0.1.4
## [37] farver_2.1.1 generics_0.1.3 jsonlite_1.8.2
## [40] crosstalk_1.2.0 googlesheets4_1.0.1 magrittr_2.0.3
## [43] Rcpp_1.0.9 munsell_0.5.0 fansi_1.0.3
## [46] lifecycle_1.0.3 stringi_1.7.8 yaml_2.3.5
## [49] grid_4.2.1 promises_1.2.0.1 crayon_1.5.2
## [52] haven_2.5.1 hms_1.1.2 ps_1.7.1
## [55] knitr_1.40 pillar_1.8.1 uuid_1.1-0
## [58] markdown_1.1 reprex_2.0.2 glue_1.6.2
## [61] evaluate_0.17 leaflet.providers_1.9.0 data.table_1.14.2
## [64] modelr_0.1.9 vctrs_0.5.0 tzdb_0.3.0
## [67] httpuv_1.6.6 cellranger_1.1.0 gtable_0.3.1
## [70] assertthat_0.2.1 cachem_1.0.6 xfun_0.37
## [73] mime_0.12 xtable_1.8-4 broom_1.0.1
## [76] later_1.3.0 ragg_1.2.3 googledrive_2.0.0
## [79] viridisLite_0.4.1 gargle_1.2.1 memoise_2.0.1
## [82] ellipsis_0.3.2