# Install and load necessary libraries
#install.packages("knitr")
#install.packages("kableExtra")
rm(list = ls())
library(knitr)
library(kableExtra)
library(dplyr)
library(here)
library(ggplot2)
library(tidyr)

Import data and clean. Dropping if answer to question “Do you contribute to landscaping choices” is missing or No.

# Import CSV file
file_path <- here("Final Landscape Transition Survey.csv")  # Update with the correct path
raw_data <- read.csv(file_path, stringsAsFactors = FALSE)
# Drop some variables
drop <- c("Collector.ID", "IP.Address", "Email.Address", "First.Name", "Last.Name", "Custom.Data.1")
raw_data <- raw_data %>% select(-one_of(drop))

# Convert contribute variable to character
#raw_data$Do.you.contribute.to.discussions.and.decisions.about.the.landscaping.and.irrigation.system.at.these.properties. <- as.character(raw_data$Do.you.contribute.to.discussions.and.decisions.about.the.landscaping.and.irrigation.system.at.these.properties.)

# Drop if no response to this variable
raw_data <- raw_data[trimws(raw_data$Do.you.contribute.to.discussions.and.decisions.about.the.landscaping.and.irrigation.system.at.these.properties.) != "", ]

# Drop if answer is no
raw_data <- raw_data %>% filter(!raw_data$Do.you.contribute.to.discussions.and.decisions.about.the.landscaping.and.irrigation.system.at.these.properties. == "No")

Function to create table for single response questions.

tabulate_and_style <- function(data,column_name,table_title) {
  # Exclude First Row
  data_subset <- data[-1, ]
  # Tabulate values of column 
  tabulated_values <- table(data_subset[[column_name]])
  # Convert to DF
  tabulated_df <- as.data.frame(tabulated_values)
  tabulated_df$Var1 <- as.character(tabulated_df$Var1)
  tabulated_df$Var1 <- replace(tabulated_df$Var1, tabulated_df$Var1 == "", "Missing")
  # Names in table 
  colnames(tabulated_df) <- c("Value", "Count")
  # Create and style the table
  styled_table <- kable(tabulated_df, format = "html", col.names = c("Value", "Count"), digits = 0) %>%
    kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive"), full_width = F) %>%
    column_spec(1, bold = TRUE) %>%
    add_header_above(setNames(ncol(tabulated_df), table_title))
  
  return(styled_table)
}

Create a function to extract counts of “Check all that apply” questions

extract_unique_and_count <- function(data, variables, table_title) {
  results <- data.frame(Category = character(),
                        Count = integer(),
                        stringsAsFactors = FALSE)
  
  for (var in variables) {
    # Filter out the non-empty values
    non_empty_values <- data[[var]][data[[var]] != ""]
    
    # Extract the unique value
    unique_value <- unique(non_empty_values)
    
    # Count the number of non-empty values. Subtract 1 for first row
    count_non_empty <- length(non_empty_values)-1
    
    # Store the results
    results <- rbind(results, data.frame(Category = ifelse(length(unique_value) == 0, NA, unique_value),
                                         Count = count_non_empty,
                                         stringsAsFactors = FALSE))
  }
  
  return(kable(results, format = "html", caption = paste0("<b>", table_title, "</b")) %>%
           kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive"), full_width = F)) 
}
tabulate_and_style(raw_data, "Which.best.describes.your.professional.role.", "Professional Role")
Professional Role
Value Count
I manage a business property. 17
I manage properties like apartments or homeowners associations. 18
I own a business property. 23
I work for a government agency that deals with parks or local areas. 14
I work for a non-profit organization. 8
I’m a consultant or work for a company that helps with outdoor water projects. 7
I’m part of a homeowners association or similar group. 8
Other (please specify) 10
tabulate_and_style(raw_data, "X", "Other Profession")
Other Profession
Value Count
Missing 95
Adu owner 1
Duplex owner/manager 1
I design landscapes and irrigation to meet WELO 1
I own a few rental properties that are in property 1
I work at a utility 1
Milti-family owner 1
Multi unit 1
Own small rental property 1
Regional water provider 1
Researcher 1
tabulate_and_style(raw_data, "What.city.", "What City")
What City
Value Count
Missing 8
Bend 1
Ashburn 1
bend 2
Bend 35
BEND 1
Bend 1
Bend, Eugene, Medford, Roseburg, Coos Bay, Kfalls & Newport 1
Bendf 1
Berthoud 1
Bessemer 1
Brooklyn 1
Camarillo 1
Canyon Lake 1
Celebration 1
Central Valley 1
City of Bend 1
City of Fort Collins 1
Fort Worth 1
Frisco 1
Geneva 1
Gilbert 5
HIALEAH 1
Indian Harbour Beach 1
Indianapolis 1
INDIANOLA 1
Irvine 1
Jacksonville 1
juu 1
Mesa 3
Milpitas 1
NEWARK 2
newyork 1
Northwood 1
Oakland 1
Oklahoma City 1
Phoenix 1
Portland 1
powell butte 1
Salt Lake City 3
San Antonio 1
San Antonio 1
San Francisco 1
San Luis Obispo 4
Santa Rosa 1
Santa Rosa 1
Seattle 1
Stockton 1
tampa 1
Torrance 1
Woodstock 1
tabulate_and_style(raw_data, "What.state.", "What State")
What State
Value Count
Missing 3
Alabama 2
Arizona 9
California 15
Colorado 4
Connecticut 1
Delaware 1
Florida 6
Georgia 3
Illinois 1
Indiana 1
New Hampshire 1
New Jersey 2
New York 1
Oregon 45
Texas 5
Utah 3
Virginia 1
Washington 1
variable <- c("Which.categories.best.describe.the.main.types.of.properties.you.or.the.organization.you.work.for.owns.or.manages...Check.all.that.apply.","X.1","X.2","X.3","X.4","X.5")
extract_unique_and_count(raw_data,variable,"Types of Properties Managed")
Types of Properties Managed
Category Count
Commercial (Automotive, Shopping Center, etc.) 31
Industrial (Manufacturing, Factory, Warehouse, etc.) 19
Institutional (Schools, Health Care Facilities) 19
Multi-family (e.g., apartments) common space 35
HOA common space 24
Municipal/government facilities (public green spaces or parks) 15

Other Category for types of properties

tabulate_and_style(raw_data, "X.6", "Other Property")
Other Property
Value Count
Missing 142
Adu 1
business common area 1
Medical Office 1
N/A 1
Office 1
Office Building property 1
Own Duplex, triplex, single family, small commercial 1
Research 1
residential 1
Senior Services/Nutrition/Information and Referral Agency 1
Theme Parks, Resorts, Hospitality 1
Water Utility 1
tabulate_and_style(raw_data, "Is.your.property.s.current.landscape.a.high..medium..or.low.water.use.landscape.", "Current Landscape Type")
Current Landscape Type
Value Count
Missing 59
High - mostly comprised of turfgrass/lawn 27
Low - only xeric or native plantings 20
Medium - mixed/mostly shrubs 48

Need to fix order of responses.

tabulate_and_style(raw_data, "Overall..how.satisfied.are.you.with.your.current.landscape.", "Satisfied with current landscape")
Satisfied with current landscape
Value Count
Missing 11
Dissatisfied 4
Neither satisfied nor dissatisfied 24
Satisfied 24
Somewhat dissatisfied 7
Somewhat satisfied 35
variable <- c("Why.do.you.have.the.landscape.or.irrigation.system.that.you.currently.have...Check.all.that.apply.
","X.7","X.8","X.9","X.10","X.11","X.12","X.13","X.14","X.15","X.16","X.17","X.18")
extract_unique_and_count(raw_data,variable, "Why do you have the landscape or irrigation system that you currently have?")
Why do you have the landscape or irrigation system that you currently have?
Category Count
NA -1
Easy to maintain 47
Curb appeal and appearance 34
Functionality (for example, outdoor gathering or eating space) 23
Trees provide shade and reduce heat 24
Doesn’t require much water 30
Comply with regulations 9
Financial incentives 6
Meet corporate or other sustainability goals 10
HOA requirements 12
Ecological considerations (native plants, biodiversity) 16
Drought resilience 14
Other (please specify) 16
tabulate_and_style(raw_data, "To.what.extent.do.you.monitor.your.water.use.on.your.property.ies..", "To what extent do you monitor your water use? ")
To what extent do you monitor your water use?
Value Count
Missing 14
I don’t see the bill or have access to water use information 2
Not closely at all - review utility costs as a whole on a yearly basis 11
Somewhat closely - monitor water use on a monthly basis 59
Very closely - monitor water use on a weekly basis 19
tabulate_and_style(raw_data, "On.a.scale.of.1.to.5..how.big.of.a.concern.are.your.property.s.water.costs.", "How big of a concern are water costs?")
How big of a concern are water costs?
Value Count
Missing 16
1 (not a concern) 4
2 13
3 37
4 22
5 (a big concern) 13
tabulate_and_style(raw_data, "To.what.extent.do.you.agree..I.can.meaningfully.lower.my.water.bill.by.using.less.water.", "I can meaningfully lower my water bill by using less water.")
I can meaningfully lower my water bill by using less water.
Value Count
Missing 15
Neither agree nor disagree 21
Somewhat agree 34
Somewhat disagree 7
Strongly Agree 26
Strongly Disagree 2
variable <- c("Who.is.the.ultimate.decision.maker.about.the.landscaping.and.irrigation.systems.at.these.properties...Select.up.to.2.
","X.19","X.20","X.21","X.22","X.23","X.24","X.25")
extract_unique_and_count(raw_data,variable, "Who makes decisions about landscaping on your properties?")
Who makes decisions about landscaping on your properties?
Category Count
NA -1
Corporate, out-of-state, decision makers within my company 12
Property owner (not my company) 19
Property management company 14
Landscape or irrigation contractor 11
Homeowner Association (HOA) 11
In-house groundskeepers or facility managers 6
Other (please specify) 17

Other Category for who makes decisions

tabulate_and_style(raw_data, "X.25", "Other Decisions")
Other Decisions
Value Count
Missing 88
City of Bend 1
Executive Director -myself 1
I am 1
I am property owner and property manager 1
I suppose we are but we need to meet City’s requirements? 1
Me 2
Me, the business owner 1
Me, the owner 1
Myself 2
Myself and maintenance person 1
nonprofit leadership who built the facility - my husband and me 1
Ourselves as orners/occupsnts 1
the HOA board ( I am not on the board) 1
we are the homeowners that fit this description 1
variable <- c("Who.else.is.consulted.or.contributes.to.decisions.about.the.landscaping.and.irrigation.system.at.these.properties...Check.all.that.apply.","X.26","X.27","X.28","X.29","X.30","X.31","X.32")
extract_unique_and_count(raw_data,variable, "Who else makes decisions about landscaping on your properties?")
Who else makes decisions about landscaping on your properties?
Category Count
Local decision makers within my company 22
Corporate, out-of-state, decision makers within my company 9
Property owner (not my company) 19
Property management company 22
Landscape or irrigation contractor 27
Homeowner Association (HOA) 20
In-house groundskeepers or facility managers 12
Other (please specify) 10

Other Category for who makes decisions

tabulate_and_style(raw_data, "X.32", "Other Decisions")
Other Decisions
Value Count
Missing 95
Academic faculty at my institution 1
Board of Directors 1
City Council - Land Use Code standards 1
faculty at OSU cascades invested in irrigation/native plants 1
Myself 2
none 1
only specific people who speak up at meetings, mostly ignored 1
owner manager role 1
variable <- c("Who.maintains.and.manages.the.landscape.and.irrigation.system.at.these.properties...Check.all.that.apply.","X.33","X.34","X.35")
extract_unique_and_count(raw_data,variable, "Who maintains the landscaping on your properties?")
Who maintains the landscaping on your properties?
Category Count
In-house groundskeepers or facility managers 22
Third-party landscaping and/or irrigation contractors 37
Mix of both 16
Other (please specify) 14

Other Category for who maintains

tabulate_and_style(raw_data, "X.35", "Other Maintains")
Other Maintains
Value Count
Missing 91
Contractor and volunteers 1
hired landscape contractors(who follow the Board’s direction) 1
me 1
Me 2
Myself and maintenance person 1
Ovcupsnts 1
owner 1
Property mgr and myself 1
property owner 1
Property owner 1
staff at nonprofit - but there is really not much management needed since it was designed to be native with no irrigation needs 1
we as landowners do 1
tabulate_and_style(raw_data,"In.the.last.10.years..has.your.organization.considered.or.implemented.projects.to.make.the.landscape.more.sustainable..such.as.removing.grass..improving.irrigation.efficiency..converting.to.native.plants..low.water.use...capturing.and.reusing.rainwater..or.managing.stormwater.on.your.site.",
 "Implemented")
Implemented
Value Count
Missing 18
Considered, but didn’t develop plans 18
Developed plans, but didn’t implement 20
Have not considered 14
Implemented 35
variable <- c("You.indicated.your.organization.has.implemented.projects.to.make.your.landscape.more.sustainable..What.changes.were.made...Check.all.that.apply.",   "X.36", "X.37", "X.38", "X.39", "X.40", "X.41", "X.42")
extract_unique_and_count(raw_data,variable, "What changes were made?")
What changes were made?
Category Count
Removed of grass 15
Installed low water use plants or grasses 28
Installed rainwater or stormwater capture or reuse systems 7
Installed efficient irrigation equipment 23
Installed a smart and/or centralized irrigation controller 18
Expanded permeable areas (places where water can soak into the soil) by reducing pavement and/or other impermeable areas 5
Planted trees to add shade 9
Other (please specify) 3

Other Category for who changes

tabulate_and_style(raw_data, "X.42", "Other Changes")
Other Changes
Value Count
Missing 102
Installed turf 1
Irrigation audits 1
Water less frequently and removed some plants 1

Histogram

tabulate_and_style(raw_data, "What.percentage.of.the.landscape.or.irrigation.system.was.changed.improved.", "What percentage was changed?")
What percentage was changed?
Value Count
Missing 70
10 2
100 3
11 1
12 1
15 1
20 1
25 3
27 1
30 2
33 1
50 6
51 2
56 1
58 1
69 1
74 1
77 1
81 1
85 2
96 1
99 2
variable <- c("What.are.the.main.reasons.for.the.changes...Select.up.to.3.",    "X.43", "X.44", "X.45", "X.46", "X.47", "X.48", "X.49", "X.50", "X.51", "X.52", "X.53", "X.54")
extract_unique_and_count(raw_data,variable, "Why did you make the changes?")
Why did you make the changes?
Category Count
Keep water bills low 12
Easy to maintain 20
Curb appeal and appearance 9
Functionality (for example, outdoor gathering or eating space) 2
Trees provide shade and reduce heat 3
Doesn’t require much water 11
Comply with regulations 1
Financial incentives 1
Meet corporate or other sustainability goals 3
HOA requirements 3
Ecological considerations (native plants, biodiversity) 10
Drought resilience 12
Other (please specify) 2

Other Category for why changes

tabulate_and_style(raw_data, "X.42", "Other Why Changes")
Other Why Changes
Value Count
Missing 102
Installed turf 1
Irrigation audits 1
Water less frequently and removed some plants 1
tabulate_and_style(raw_data, "Have.these.projects.saved.money.on.landscape.and.or.irrigation.operations.and.maintenance..O.M..costs.", "Did the projects save money on O&M costs?")
Did the projects save money on O&M costs?
Value Count
Missing 71
I’m not sure 7
No 6
Yes 21
tabulate_and_style(raw_data, "Have.these.projects.saved.money.on.water.bills.", "Have the projects saved money on water bills?")
Have the projects saved money on water bills?
Value Count
Missing 71
I’m not sure 8
No 5
Yes 21
variable <- c("Were.there.any.additional.project.benefits...Check.all.that.apply.", "X.55", "X.56", "X.57", "X.58", "X.59", "X.60", "X.61", "X.62", "X.63", "X.64", "X.65", "X.66", "X.67", "X.68")
extract_unique_and_count(raw_data,variable, "Were there other benefits to the project?")
Were there other benefits to the project?
Category Count
Reduced outdoor water use 17
Reduced site operation and maintenance costs 16
Reduced energy usage 6
Captured stormwater/rainwater available for reuse onsite 4
Water captured onsite recharged into groundwater basin 2
Reduced quantity of runoff from site 3
Improved quality of runoff from site 2
Improved aesthetics 15
Improved public perception (reputation/brand image) 7
Created pollinator (bee) and bird habitat with native plants 7
Reduced use of chemicals, fertilizers and pesticides 9
Improved functionality (e.g., outdoor gathering spaces) 5
Increased drought and heat tolerance 10
More shade and reduced urban heat effect 4
Other (please specify) 0

Other Category for why changes

tabulate_and_style(raw_data, "X.68", "Other Additional Benefits")
Other Additional Benefits
Value Count
Missing 105
tabulate_and_style(raw_data, "To.what.extent.do.you.agree..There.is.more.we.could.do.to.reduce.outdoor.water.use.on.the.property.", "There is more we could do to reduce water use.")
There is more we could do to reduce water use.
Value Count
Missing 71
Neither Agree nor Disagree 10
Somewhat Agree 11
Somewhat Disagree 3
Strongly Agree 8
Strongly Disagree 2
tabulate_and_style(raw_data, "How.much.of.the.remaining.landscape.might.you.be.willing.to.change.in.the.future...0.100..", "How much would you be willing to change in the future?")
How much would you be willing to change in the future?
Value Count
Missing 75
0 2
10 3
100 3
12 1
17 1
20 1
25 5
27 1
35 2
36 1
49 1
50 5
70 1
77 1
85 1
87 1