# plot RL_NOISE vs FA, BA, EC, ES, with a smoothing line each (one plot per y)# create first dataset that only contains relevant variables for the folowing plotsD.plot <- D[, c("HM_NOISE", "RL_NOISE", "HM_NDVI", "RL_NDVI", "FA", "BA", "EC", "ES")]D.plot <-pivot_longer(D.plot, cols =c("FA", "BA", "EC", "ES"), names_to ="Variable", values_to ="Value")# plot RL_NOISE vs FA, BA, EC, ES, with a smoothing line each (one plot per y)ggplot(D.plot, aes(x = HM_NOISE, y = Value, color = Variable)) +geom_vline(xintercept =c(45, 55), linetype ="dashed", color ="gray", linewidth =1.3) +geom_smooth(method ="gam", se =TRUE, alpha =0.25, linewidth =1.5, formula = y ~s(x, bs ="cs")) +labs(x ="Home Noise Level [dB]",y ="Response Value",color ="Variable" ) +theme(legend.position ="bottom")
Plot PRS ~ HM_NOISE or RL_NOISE
# reproduce the plot above with the long format dataggplot(D.plot, aes(x = RL_NOISE, y = Value, color = Variable)) +geom_vline(xintercept =c(45, 55), linetype ="dashed", color ="gray", linewidth =1.3) +geom_smooth(method ="gam", se =TRUE, alpha =0.25, linewidth =1.5, formula = y ~s(x, bs ="cs")) +theme(legend.position ="bottom")
RL ~ HM — for NOISE and NDVI
In [6]:
Plot RL ~ HM for NOISE and NDVI
# plot RL_NOISE vs HM_NOISE with a smoothing linecggplot(D, aes(x = HM_NOISE, y = RL_NOISE)) +geom_vline(xintercept =c(45, 55), linetype ="dashed", color ="gray", linewidth =1.3) +geom_abline(slope =1, intercept =0, linetype ="dashed", color ="black", linewidth =1) +geom_point(alpha =0.3) +geom_smooth(method ="gam", se =TRUE, alpha =0.3, formula = y ~s(x, bs ="cs")) +labs(x ="HM_NOISE [dB]",y ="RL_NOISE [dB]" ) +coord_obs_pred() # for aspect ratio 1:1
Plot RL ~ HM for NOISE and NDVI
# plot (RL_NDVI vs HM_NDVI with a smoothing line) + an identity lineggplot(D, aes(x = HM_NDVI, y = RL_NDVI)) +geom_abline(slope =1, intercept =0, linetype ="dashed", color ="black", linewidth =1) +geom_point(alpha =0.3) +geom_smooth(method ="gam", se =TRUE, alpha =0.3, linewidth =1.5, formula = y ~s(x, bs ="cs")) +coord_obs_pred() # for aspect ratio 1:1
LNOISE ~ HM_NOISE or RL_NOISE
In [7]:
Plot LNOISE ~ HM_NOISE or RL_NOISE
# plot HM_NOISE vs LNOISE with a smooth line (and small jitter sd=0.2)ggplot(D, aes(x = HM_NOISE, y = LNOISE)) +geom_vline(xintercept =c(45, 55), linetype ="dashed", color ="gray", linewidth =1.3) +geom_jitter(width =0.1, height =0.2, alpha =0.3) +geom_smooth(method ="gam", se =TRUE, alpha =0.3, formula = y ~s(x, bs ="cs")) +labs(x ="HM_NOISE [dB]",y ="LNOISE" )
Plot LNOISE ~ HM_NOISE or RL_NOISE
# repeat for RL_NOISEggplot(D, aes(x = RL_NOISE, y = LNOISE)) +geom_vline(xintercept =c(45, 55), linetype ="dashed", color ="gray", linewidth =1.3) +geom_jitter(width =0.1, height =0.2, alpha =0.3) +geom_smooth(method ="gam", se =TRUE, alpha =0.3, formula = y ~s(x, bs ="cs"))
ADD proportions
In [8]:
Compute proportions of LNOISE levels for each HM_NOISELVL/RL_NOISELVL
# Define at cutof 45 and 55 dBD$HM_NOISELVL <-cut(D$HM_NOISE, breaks =c(-Inf, 45, 55, Inf), labels =c("Low", "Medium", "High"))D$RL_NOISELVL <-cut(D$RL_NOISE, breaks =c(-Inf, 45, 55, Inf), labels =c("Low", "Medium", "High"))# Get marginal percentage (how many in which LNOISE lvl) for each level of HM_NOISELVL/RL_NOISELVLHM_tab <-xtabs(~ HM_NOISELVL + LNOISE, D)RL_tab <-xtabs(~ RL_NOISELVL + LNOISE, D)HM_tab_prop <- (100*prop.table(HM_tab, margin =1)) |>round(1) RL_tab_prop <- (100*prop.table(RL_tab, margin =1)) |>round(1)# HM.df <- as.data.frame(HM_tab)# RL.df <- as.data.frame(RL_tab)HM_prop.df <-as.data.frame(HM_tab_prop)RL_prop.df <-as.data.frame(RL_tab_prop)# add X, with the dict according to NOISELVL Low = 38, Medium = 48, High = 58dict <-c("Low"=37.5, "Medium"=50, "High"=62.5)HM_prop.df$HM_NOISELVL <- dict[HM_prop.df$HM_NOISELVL]RL_prop.df$RL_NOISELVL <- dict[RL_prop.df$RL_NOISELVL]HM_prop.df$LNOISE <-as.numeric(HM_prop.df$LNOISE)RL_prop.df$LNOISE <-as.numeric(RL_prop.df$LNOISE)
In [9]:
Repeat plots, but add marginal percentages as text
# repeat plots, but add the marginal percentages as textggplot(D, aes(x = HM_NOISE, y = LNOISE)) +geom_vline(xintercept =c(45, 55), linetype ="dashed", color ="gray", linewidth =1.3) +geom_jitter(width =0.1, height =0.2, alpha =0.2) +geom_smooth(method ="gam", se =TRUE, alpha =0.3, formula = y ~s(x, bs ="cs")) +labs(x ="HM_NOISE [dB]",y ="LNOISE" ) +geom_text(data = HM_prop.df, aes(x = HM_NOISELVL, y = LNOISE, label =paste0(Freq, "%")), size =7, col ="darkorange")
Repeat plots, but add marginal percentages as text
ggplot(D, aes(x = RL_NOISE, y = LNOISE)) +geom_vline(xintercept =c(45, 55), linetype ="dashed", color ="gray", linewidth =1.3) +geom_jitter(width =0.1, height =0.2, alpha =0.2) +geom_smooth(method ="gam", se =TRUE, alpha =0.3, formula = y ~s(x, bs ="cs")) +labs(x ="RL_NOISE [dB]",y ="LNOISE" ) +geom_text(data = RL_prop.df, aes(x = RL_NOISELVL, y = LNOISE, label =paste0(Freq, "%")), size =7, col ="darkorange")