Skip to content

Commit 274c56f

Browse files
committed
fixed community selection logic to match plot function
1 parent 7aa8b6a commit 274c56f

1 file changed

Lines changed: 40 additions & 11 deletions

File tree

R/plot_community_factors.R

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,19 @@ plot_community_factors <- function(
5757
)
5858
}
5959

60-
fix <- ecodata::engagement |>
60+
eng <- ecodata::engagement |>
61+
#dplyr::distinct(Time, Var, EPU, Units, .keep_all = T) |> #hack, remove later
6162
tidyr::separate(Var, into = c("Town", "StateVar"), sep = ", ") |> #using two steps because some towns have - in the name
6263
tidyr::separate(StateVar, into = c("State", "Var"), sep = "-") |> # which also seps the variable
6364
tidyr::unite("Town", c(Town, State), sep = ",") |>
65+
dplyr::mutate(Town = dplyr::case_when(
66+
stringr::str_detect(Town, "OTHER,VA") ~ "OTHER,VA (includes REEDVILLE)",
67+
stringr::str_detect(Town, "Bronx/City Island") ~ "BRONX,NY",
68+
stringr::str_detect(Town, "Reedville/District 5") ~ "Reedville,VA",
69+
stringr::str_detect(Town, "Harpswell/Bailey Island") ~ "Harpswell,ME",
70+
stringr::str_detect(Town, "South Kingstown/Kingston/Wakefield-Peacedale") ~ "South Kingstown,RI",
71+
TRUE ~ Town # This keeps everything else the same
72+
))|>
6473
# tidyr::pivot_wider(names_from = Var, values_from = Value) |>
6574
dplyr::filter(EPU == filterEPUs) |>
6675
tidyr::separate(
@@ -72,22 +81,42 @@ plot_community_factors <- function(
7281
dplyr::mutate(city = stringr::str_to_title(city)) |>
7382
tidyr::unite("Town", city, state, sep = ", ")
7483

75-
all.towns = fix |>
76-
dplyr::filter(!(Var %in% ('fishing_mean_score'))) |>
77-
dplyr::pull(Town) |>
78-
unique() |>
79-
tolower()
84+
eng.ts = eng |>
85+
dplyr::filter(Var == 'fishing_mean_score') |>
86+
dplyr::mutate(
87+
label = dplyr::if_else(
88+
Time == max(Time),
89+
as.character(Town),
90+
NA_character_
91+
)
92+
)
8093

81-
top.coms = fix |>
82-
dplyr::filter(Var == filterVar & !is.na(Value)) |>
83-
dplyr::filter(Time == max(Time) & tolower(Town) %in% all.towns) |>
94+
top.coms <- eng |>
95+
dplyr::filter(Time == max(Time)) |>
8496
dplyr::arrange(desc(Value)) |>
85-
dplyr::slice_head(n = n) |>
97+
head(n = 10) |>
98+
dplyr::mutate(
99+
Town = dplyr::recode(Town, "Other, VA (includes REEDVILLE)" = "Reedville, VA")
100+
) |>
86101
dplyr::pull(Town)
87102

103+
#
104+
# all.towns = fix |>
105+
# dplyr::filter(!(Var %in% ('fishing_mean_score'))) |>
106+
# dplyr::pull(Town) |>
107+
# unique() |>
108+
# tolower()
109+
#
110+
# top.coms = fix |>
111+
# dplyr::filter(Var == filterVar & !is.na(Value)) |>
112+
# dplyr::filter(Time == max(Time) & tolower(Town) %in% all.towns) |>
113+
# dplyr::arrange(desc(Value)) |>
114+
# dplyr::slice_head(n = n) |>
115+
# dplyr::pull(Town)
116+
88117
# optional code to wrangle ecodata object prior to plotting
89118
# e.g., calculate mean, max or other needed values to join below
90-
data = fix |>
119+
data = eng |>
91120
dplyr::filter(Var %in% indgroup) |>
92121
dplyr::group_by(Town) |>
93122
dplyr::mutate(total = sum(Value, na.rm = T)) |>

0 commit comments

Comments
 (0)