Skip to content

Commit

Permalink
update logistic regression example fig
Browse files Browse the repository at this point in the history
  • Loading branch information
fawda123 committed Sep 4, 2024
1 parent aceee5d commit 220f218
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions R/logistic_ex.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ toplo <- toprd |>
prd = prds$fit,
hival = prds$fit + 1.96 * prds$se.fit,
loval = prds$fit - 1.96 * prds$se.fit,
Turbidity = factor( Turbidity, labels = c('95th %tile','mean'), levels = unique(Turbidity) )
Turbidity = factor( Turbidity, labels = c('Elevated','Normal'), levels = unique(Turbidity) )
)

# get lines to show connection between hypothetical target and certainty of meeting threshold
Expand All @@ -45,24 +45,28 @@ tolns <- trgs |>
prd = lnprds$fit,
hival = lnprds$fit + 1.96 * lnprds$se.fit,
loval = lnprds$fit - 1.96 * lnprds$se.fit,
Turbidity = factor( Turbidity, labels = c('95th %tile','mean'), levels = unique(Turbidity) )
Turbidity = factor( Turbidity, labels = c('Elevated','Normal'), levels = unique(Turbidity) )
)

# plot
p <- ggplot(toplo, aes(x = value, y = prd, fill = Turbidity, color = Turbidity, group = Turbidity)) +
geom_ribbon(aes(ymin = loval, ymax = hival), alpha = 0.2) +
geom_line() +
geom_segment(data = tolns, aes(x = value, xend = value, y = 0, yend = hival), linetype = 'dashed', inherit.aes = F) +
geom_segment(data = tolns, aes(x = 0, xend = value, y = loval, yend = loval), linetype = 'dashed') +
geom_segment(data = tolns, aes(x = 0, xend = value, y = hival, yend = hival), linetype = 'dashed') +
p <- ggplot(toplo, aes(x = value, y = prd, group = Turbidity)) +
geom_ribbon(aes(ymin = loval, ymax = hival, fill = Turbidity), alpha = 0.2) +
geom_line(aes(color = Turbidity)) +
geom_segment(data = tolns, aes(color = Turbidity, x = value, xend = value, y = 0, yend = prd), linetype = 'dashed', inherit.aes = F) +
geom_segment(data = tolns, aes(color = Turbidity, x = 0, xend = value, y = prd, yend = prd), linetype = 'dashed') +
# geom_segment(data = tolns, aes(x = 0, xend = value, y = hival, yend = hival), linetype = 'dashed') +
scale_color_manual(values = c('tomato1', 'dodgerblue')) +
scale_fill_manual(values = c('tomato1', 'dodgerblue')) +
coord_cartesian(xlim = c(0, 200)) +
theme_minimal() +
theme(legend.position = 'top') +
labs(
x = 'Monthly TN load',
y = 'Probability of attaining 9.3 µg/L',
caption = 'Hypothetical example of how to use model to set TN load targets'
)
x = 'Monthly nitrogen load',
fill = 'Climate condition',
color = 'Climate condition',
y = 'Probability of meeting water quality goal'
)

png(here::here('figs/logisticex.png'), width = 6, height = 4, units = 'in', res = 300)
png(here::here('figs/logisticex.png'), width = 5, height = 4, units = 'in', res = 300)
print(p)
dev.off()
Binary file modified figs/logisticex.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 220f218

Please sign in to comment.