diff --git a/ironwood_data_cleaned.ods b/ironwood_data_cleaned.ods index 613dd8c..68a5a11 100644 Binary files a/ironwood_data_cleaned.ods and b/ironwood_data_cleaned.ods differ diff --git a/ironwood_plots.R b/ironwood_plots.R index a444949..5417dc1 100644 --- a/ironwood_plots.R +++ b/ironwood_plots.R @@ -8,14 +8,18 @@ library(dplyr) library(leaflet) ## -# parse the input data +# parse the input data and declare global values ## # read a data frame from the ods document df <- read_ods("ironwood_data_cleaned.ods", sheet = 1) - -# Output the results -print(df) +# site base location +site_lat <- "-33.943917" +site_lon <- "23.507389" +# vector of condition names corresponding to the health index numbers +condition_names <- c("healthy", "light damage", "medium damage", "severe damage", "at point of death") +# colors for each condition +condition_colors <- c("green", "yellow", "orange", "red", "black") ## @@ -23,16 +27,12 @@ print(df) # - create an overview of the populations health ## -# First, let's create a vector of condition names corresponding to the health index numbers -condition_names <- c("Healthy", "Light damage", "Medium damage", "Severe damage", "At point of death") -# Define colors for each condition -condition_colors <- c("green", "yellow", "orange", "red", "black") # Calculate the percentage of trees in each health condition -percentage <- prop.table(table(df$Tree_Health_Index)) * 100 +percentage <- prop.table(table(df$tree_health_index)) * 100 # Now, let's create the bar plot barplot(percentage, names.arg = condition_names, - main = "Distribution of Tree Health Index", + main = "Overview of Tree Health Index", xlab = "Health Index", ylab = "Percentage of Trees", ylim = c(0, max(percentage) + 10), @@ -43,7 +43,7 @@ legend("topright", legend = condition_names, fill = condition_colors) # Adding a grid #grid(nx = NULL, ny = NULL, col = "lightgray", lty = "dotted") # Adding a box around the plot -box() +#box() # Add labels with the percentage of trees in each bar text(x = barplot(percentage, plot = FALSE), y = percentage, labels = paste0(round(percentage, 1), "%"), pos = 3) @@ -53,7 +53,7 @@ text(x = barplot(percentage, plot = FALSE), y = percentage, labels = paste0(roun ## # Perform Shapiro-Wilk test -shapiro_test <- shapiro.test(df$Tree_Health_Index) +shapiro_test <- shapiro.test(df$tree_health_index) # Print the test results print(shapiro_test) # Check the p-value @@ -65,15 +65,30 @@ if (p_value < 0.05) { print("The data is normally distributed (fail to reject the null hypothesis)") } - ## # 3. try to fit health and location data in one plot ## -sites <- data.frame( - id = 1:20, - lat = -) +# create a map from our base location +map <- leaflet() %>% + setView(lng = site_lon, + lat = site_lat, + zoom = 16) %>% + addProviderTiles("CartoDB.Positron") + +# Add markers with varying color and size based on population health and number of trees +map <- map %>% + addCircleMarkers( + data = df, + lng = ~tree_lon, + lat = ~tree_lat, + radius = 5, + color = ~condition_colors[tree_health_index+1], + fillOpacity = 0.7 + ) + +# show map +map ## # ToDo Tasks: