update readme, and plot

This commit is contained in:
aaron
2024-06-10 18:29:00 +02:00
parent 06d306afa1
commit fc798080be
3 changed files with 7 additions and 3 deletions

View File

@@ -1 +1,5 @@
# ironwood plots # ironwood plots
Ironwood tree healh data analysis using R.
![ironwood tree health map](health_map_plot.png)

BIN
health_map_plot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 MiB

View File

@@ -6,6 +6,7 @@ library(readODS)
library(tidyverse) library(tidyverse)
library(dplyr) library(dplyr)
library(leaflet) library(leaflet)
library(RColorBrewer)
## ##
# parse the input data, declare global values and auxiliary data # parse the input data, declare global values and auxiliary data
@@ -68,6 +69,7 @@ health_counts <- df %>%
# Pivot the data frame to wide format for ggplot # Pivot the data frame to wide format for ggplot
health_counts_wide <- pivot_wider(health_counts, names_from = tree_health_index, values_from = count, values_fill = list(count = 0)) health_counts_wide <- pivot_wider(health_counts, names_from = tree_health_index, values_from = count, values_fill = list(count = 0))
# plot each bar
ggplot(health_counts_wide, aes(x = site_num)) + ggplot(health_counts_wide, aes(x = site_num)) +
geom_bar(aes(fill = `0`), position = "stack", width = 0.5) + geom_bar(aes(fill = `0`), position = "stack", width = 0.5) +
geom_bar(aes(fill = `1`), position = "stack", width = 0.5) + geom_bar(aes(fill = `1`), position = "stack", width = 0.5) +
@@ -78,12 +80,10 @@ ggplot(health_counts_wide, aes(x = site_num)) +
scale_fill_manual(values = c("#1b9e77", "#d95f02", "#7570b3", "#e7298a", "#66a61e")) + # Custom colors for each health index scale_fill_manual(values = c("#1b9e77", "#d95f02", "#7570b3", "#e7298a", "#66a61e")) + # Custom colors for each health index
theme_minimal() theme_minimal()
# rename
colnames(health_data) <- paste("Site", seq(1,20), sep=" ") colnames(health_data) <- paste("Site", seq(1,20), sep=" ")
rownames(health_data) <- condition_names rownames(health_data) <- condition_names
# create color palette: # create color palette:
library(RColorBrewer)
coul <- brewer.pal(3, "Pastel2") coul <- brewer.pal(3, "Pastel2")
# Transform this data in % # Transform this data in %
data_percentage <- apply(data, 2, function(x){x*100/sum(x,na.rm=T)}) data_percentage <- apply(data, 2, function(x){x*100/sum(x,na.rm=T)})