# Create Plot 1: Dominating Sounds ---------------
D_long <- D |>
pivot_longer(
cols = starts_with("LDOMAUD"),
names_to = "Sound_Type",
values_to = "Value"
)
# rename the sound types for better readability
D_long$Sound_Type <- recode(D_long$Sound_Type,
LDOMAUD1 = "Nature sounds",
LDOMAUD2 = "Human sounds",
LDOMAUD3 = "Traffic sounds",
LDOMAUD4 = "Other technical noises"
)
p_dominating_sound <- ggplot(D_long, aes(x = RL_NOISE, y = Value, color = Sound_Type)) +
geom_smooth(method = "gam", se = TRUE, alpha = 0.3, size = 1.2, formula = y ~ s(x, bs = "cs")) +
ylim(1, 5) +
ylab("Response [1-5]") +
labs(title = "a. Sound type")
# Create Plot 2: Soundscape Attributes ---------------
D_long <- D |>
pivot_longer(
cols = starts_with("LSOUNDS"),
names_to = "Attribute",
values_to = "Value"
)
# rename the attributes for better readability
D_long$Attribute <- recode(D_long$Attribute,
LSOUNDS1 = "Pleasant",
LSOUNDS2 = "Chaotic",
LSOUNDS3 = "Vibrant",
LSOUNDS4 = "Uneventful",
LSOUNDS5 = "Tranquil",
LSOUNDS6 = "Bothering",
LSOUNDS7 = "Eventful",
LSOUNDS8 = "Monotone",
LSOUNDS9 = "Loud"
)
p_soundscate_attr <- ggplot(D_long, aes(x = RL_NOISE, y = Value, color = Attribute)) +
geom_smooth(method = "gam", se = TRUE, alpha = 0.3, size = 1.2, formula = y ~ s(x, bs = "cs")) +
ylim(1, 5) +
scale_color_brewer(palette = "Set1") +
ylab("Response [1-5]") +
labs(title = "b. Soundscape assessment")
# NOISE ANNOYANCE
# For the noise annoyance variables, we need to handle the character values
# Convert character annoyance values to numeric
convert_annoyance <- function(x) {
case_when(
x == "00" ~ 0,
x == "01" ~ 1,
x == "02" ~ 2,
x == "03" ~ 3,
x == "04" ~ 4,
x == "05" ~ 5,
x == "06" ~ 6,
x == "07" ~ 7,
x == "08" ~ 8,
x == "09" ~ 9,
x == "10" ~ 10,
x == "No annoyance" ~ 0,
x == "Response scale mid-point" ~ 5,
x == "Very annoying" ~ 10,
TRUE ~ as.numeric(x)
)
}
# Create a temporary data frame with converted values for noise annoyance
D_temp <- D |>
mutate(
LSANNOY1_num = convert_annoyance(LSANNOY1),
LSANNOY2_num = convert_annoyance(LSANNOY2),
LSANNOY3_num = convert_annoyance(LSANNOY3),
LSANNOY4_num = convert_annoyance(LSANNOY4),
LSANNOY5_num = convert_annoyance(LSANNOY5),
LSANNOY6_num = convert_annoyance(LSANNOY6),
LSANNOY7_num = convert_annoyance(LSANNOY7)
)
vars_tmp <- c("LSANNOY1_num", "LSANNOY2_num",
"LSANNOY3_num", "LSANNOY4_num", "LSANNOY5_num", "LSANNOY6_num", "LSANNOY7_num")
D_long_annoyance <- pivot_longer(
D_temp,
cols = all_of(vars_tmp),
names_to = "Annoyance",
values_to = "Value"
)
# rename
D_long_annoyance$Annoyance <- recode(D_long_annoyance$Annoyance,
LSANNOY1_num = "Road Traffic",
LSANNOY2_num = "Public Transport",
LSANNOY3_num = "Train",
LSANNOY4_num = "Plane",
LSANNOY5_num = "Freetime",
LSANNOY6_num = "Music of others",
LSANNOY7_num = "Works"
)
D_long_annoyance$Annoyance <- factor(D_long_annoyance$Annoyance,
levels = c("Road Traffic", "Public Transport",
"Train", "Plane", "Freetime", "Music of others", "Works")
)
p_noise_annoy <- ggplot(D_long_annoyance, aes(x = RL_NOISE, y = Value, color = Annoyance)) +
geom_smooth(method = "gam", se = TRUE, alpha = 0.3, size = 1.2, formula = y ~ s(x, bs = "cs")) +
ylim(0, 10) +
ylab("Response [0-10]") +
labs(title = "c. Noise annoyance")