update-survey-fields #1

Merged
nick merged 2 commits from update-survey-fields into master 2025-05-05 21:56:52 -04:00

View File

@ -318,8 +318,8 @@ The table below summarizes the response rates for optional top-level questions i
The "Total Number of Species Planted" question has special handling—only responses greater than 0 are considered valid, whereas for other questions, any non-NA value counts as a response.
```{r response-rate-table-optional, echo=TRUE, message=FALSE, fig.height=6, fig.width=8}
fields <- c("Planter Contact Email", "Funding Source", "Land Ownership",
"Tree Size Planted", "Source of Trees", "Total Number of Species Planted")
fields <- c("Planter Contact Email (Optional)", "Funding Source (Optional)", "Land Ownership (Optional)",
"Tree Size Planted (Optional)", "Source of Trees (Optional)", "Total Number of Species Planted")
calculate_response_rates(survey_data, fields, "Response Rates for Key Survey Questions")
```
@ -345,7 +345,7 @@ The following plot shows the distribution of survey submissions based on partici
```{r create-histogram-participant-type, echo=TRUE, message=FALSE, fig.height=6, fig.width=8}
create_histogram(
survey_data,
field = "Who Planted The Tree(s)?",
field = "Who Planted The Tree(s)? (Required)",
x_labels = c(
"agency" = "State Agency",
"community" = "Community Organization",
@ -421,7 +421,7 @@ create_bar_chart <- function(data, field, sum_field = NULL, x_labels = NULL, col
```{r create_bar_chart-participant-total-trees,echo=TRUE, message=FALSE, fig.height=6, fig.width=8}
create_bar_chart(
survey_data,
field = "Who Planted The Tree(s)?",
field = "Who Planted The Tree(s)? (Required)",
x_labels = c(
"agency" = "State Agency",
"community" = "Community Organization",
@ -429,7 +429,7 @@ create_bar_chart(
"municipality" = "Municipal Government",
"professional" = "Paid Professional"
),
sum_field = "Number of Trees Planted",
sum_field = "Number of Trees Planted (Required)",
x_title = "Participant Type",
y_title = "Total Trees Planted",
title = "Total Trees Planted by Participant Type",
@ -498,14 +498,14 @@ The following table provides a breakdown of the total number of trees planted by
```{r participant-type-table, echo=TRUE, message=FALSE, fig.height=6, fig.width=8}
survey_data %>%
mutate(
`Who Planted The Tree(s)?` = recode(`Who Planted The Tree(s)?`,
`Who Planted The Tree(s)? (Required)` = recode(`Who Planted The Tree(s)? (Required)`,
"agency" = "State Agency",
"community" = "Community Organization",
"landowner" = "Private Landowner",
"municipality" = "Municipal Government",
"professional" = "Paid Professional")
) %>%
create_summary_table("Who Planted The Tree(s)?", "Number of Trees Planted", remove_na = FALSE, table_font_size = 16)
create_summary_table("Who Planted The Tree(s)? (Required)", "Number of Trees Planted (Required)", remove_na = FALSE, table_font_size = 16)
```
## Named User Activity
@ -513,7 +513,7 @@ survey_data %>%
```{r named-user-activity-table, echo=TRUE, message=FALSE, fig.height=6, fig.width=8}
survey_data %>%
mutate(Creator = ifelse(is.na(Creator), "Public User", Creator)) %>%
create_summary_table("Creator", "Number of Trees Planted", remove_na = FALSE, table_font_size = 16)
create_summary_table("Creator", "Number of Trees Planted (Required)", remove_na = FALSE, table_font_size = 16)
```
## Unique E-mail Activity
@ -521,21 +521,21 @@ survey_data %>%
```{r unique-email-activity-table, echo=TRUE, message=FALSE, fig.height=6, fig.width=8}
survey_data %>%
mutate(Creator = ifelse(is.na(`Planter Contact Email`), "Not Provided", `Planter Contact Email`)) %>%
create_summary_table("Planter Contact Email", "Number of Trees Planted", remove_na = FALSE, table_font_size = 16)
mutate(Creator = ifelse(is.na(`Planter Contact Email (Optional)`), "Not Provided", `Planter Contact Email (Optional)`)) %>%
create_summary_table("Planter Contact Email (Optional)", "Number of Trees Planted (Required)", remove_na = FALSE, table_font_size = 16)
```
## Municipal Activity
```{r}
survey_data %>%
mutate(`Participant Municipality` = case_when(
str_starts(`Participant Municipality`, "c_") ~ str_replace(`Participant Municipality`, "^c_", "") %>% paste0(" (city)"),
str_starts(`Participant Municipality`, "v_") ~ str_replace(`Participant Municipality`, "^v_", "") %>% paste0(" (village)"),
str_starts(`Participant Municipality`, "t_") ~ str_replace(`Participant Municipality`, "^t_", "") %>% paste0(" (town)"),
TRUE ~ `Participant Municipality`
mutate(`Participant Municipality (Optional)` = case_when(
str_starts(`Participant Municipality (Optional)`, "c_") ~ str_replace(`Participant Municipality (Optional)`, "^c_", "") %>% paste0(" (city)"),
str_starts(`Participant Municipality (Optional)`, "v_") ~ str_replace(`Participant Municipality (Optional)`, "^v_", "") %>% paste0(" (village)"),
str_starts(`Participant Municipality (Optional)`, "t_") ~ str_replace(`Participant Municipality (Optional)`, "^t_", "") %>% paste0(" (town)"),
TRUE ~ `Participant Municipality (Optional)`
)) %>%
create_summary_table("Participant Municipality", "Number of Trees Planted", remove_na = FALSE, table_font_size = 16)
create_summary_table("Participant Municipality (Optional)", "Number of Trees Planted (Required)", remove_na = FALSE, table_font_size = 16)
```
## Organizaiton Activity
@ -606,7 +606,7 @@ The map provides a visual overview of tree planting distribution across New York
```{r create-region-choropleth-map, echo=TRUE, message=FALSE, fig.height=6, fig.width=8}
survey_data_aggregated <- survey_data %>%
group_by(Region) %>%
summarise(total_trees = sum(`Number of Trees Planted`, na.rm = TRUE))
summarise(total_trees = sum(`Number of Trees Planted (Required)`, na.rm = TRUE))
shapefile_path <- "/home/nick/gitea/tree-tracker-report/data/redc/redc.shp"
@ -634,7 +634,7 @@ plot_geographic_data(joined_data = survey_data_joined,
```
```{r create-summary-table-region, echo=TRUE, message=FALSE, fig.height=6, fig.width=8}
create_summary_table(survey_data, "Region", "Number of Trees Planted", remove_na = FALSE, table_font_size = 16)
create_summary_table(survey_data, "Region", "Number of Trees Planted (Required)", remove_na = FALSE, table_font_size = 16)
```
## By County
@ -650,7 +650,7 @@ The map provides a visual overview of tree planting distribution across New York
```{r create-county-choropleth-map, echo=TRUE, message=FALSE, fig.height=6, fig.width=8}
survey_data_aggregated <- survey_data %>%
group_by(County) %>%
summarise(total_trees = sum(`Number of Trees Planted`, na.rm = TRUE))
summarise(total_trees = sum(`Number of Trees Planted (Required)`, na.rm = TRUE))
geographic_data <- counties(state = "NY", cb = TRUE, progress = FALSE) %>%
st_as_sf() %>%
@ -672,7 +672,7 @@ plot_geographic_data(joined_data = survey_data_joined,
```
```{r create-summary-table-county, echo=TRUE, message=FALSE, , fig.height=6, fig.width=8}
create_summary_table(survey_data, "County", "Number of Trees Planted", remove_na = FALSE, table_font_size = 16)
create_summary_table(survey_data, "County", "Number of Trees Planted (Required)", remove_na = FALSE, table_font_size = 16)
```
@ -745,7 +745,7 @@ The following table shows a breakdown of survey submissions by **Genus**. For ea
These figures provide an understanding of which genus are most commonly reported, how prevalent each genus is, and the proportion of surveys where no genus was specified.
```{r create-summary-table-genus, echo=TRUE, message=FALSE, fig.height=6, fig.width=8}
create_species_summary_table(species_planted, "Generic Species of Tree", "Tree Genus")
create_species_summary_table(species_planted, "Generic Type of Tree (Optional)", "Tree Genus")
```
## By Species
@ -759,7 +759,7 @@ The following table shows a breakdown of survey submissions by **Species**. For
These figures provide an understanding of which species are most commonly reported, how prevalent each species is, and the proportion of surveys where no genus was specified.
```{r create-summary-table-species, echo=TRUE, message=FALSE, fig.height=6, fig.width=8}
create_species_summary_table(species_planted, "Precise Species of Tree", "Tree Species")
create_species_summary_table(species_planted, "Tree Species (Optional)", "Tree Species")
```
# Disadvantaged Communities {.tabset}
@ -768,8 +768,8 @@ create_species_summary_table(species_planted, "Precise Species of Tree", "Tree S
```{r create-summary-table-region-dac, echo=TRUE, message=FALSE, , fig.height=6, fig.width=8}
survey_data %>%
filter(`Disadvantaged Communities Indicator` == "Designated as DAC", na.rm = TRUE) %>%
create_summary_table("Region", "Number of Trees Planted", remove_na = FALSE, table_font_size = 16)
filter(!is.na(`Disadvantaged Communities Indicator`), na.rm = TRUE) %>%
create_summary_table("Region", "Number of Trees Planted (Required)", remove_na = FALSE, table_font_size = 16)
```
@ -777,15 +777,14 @@ survey_data %>%
```{r create-summary-table-county-dac, echo=TRUE, message=FALSE, , fig.height=6, fig.width=8}
survey_data %>%
filter(`Disadvantaged Communities Indicator` == "Designated as DAC", na.rm = TRUE) %>%
create_summary_table("County", "Number of Trees Planted", remove_na = FALSE, table_font_size = 16)
filter(!is.na(`Disadvantaged Communities Indicator`), na.rm = TRUE) %>%
create_summary_table("County", "Number of Trees Planted (Required)", remove_na = FALSE, table_font_size = 16)
```
## By Municipality
```{r create-summary-table-county-municipality, echo=TRUE, message=FALSE, , fig.height=6, fig.width=8}
survey_data %>%
filter(`Disadvantaged Communities Indicator` == "Designated as DAC", na.rm = TRUE) %>%
create_summary_table("Municipality", "Number of Trees Planted", remove_na = FALSE, table_font_size = 16)
filter(!is.na(`Disadvantaged Communities Indicator`), na.rm = TRUE) %>%
create_summary_table("Municipality", "Number of Trees Planted (Required)", remove_na = FALSE, table_font_size = 16)
```