Customizing Dose Response Curves in R with ggplot2's geom_ribbon

Here is a code snippet that addresses the warnings mentioned:

library(ggplot2)

# Assuming your dataframe is stored as 'df'
ggplot(df, aes(x = dose, y = probability)) +
  geom_ribbon(data = df, aes(xintercept = dose, ymin = Lower, ymax = Upper), fill = "lightblue") +
  scale_x_continuous(breaks = seq(min(df$dose), max(df$dose), by = 1)) +
  theme_classic() +
  labs(title = "Dose Response Curve", x = "Dose", y = "Probability")

Note that I’ve removed the y aesthetic from the geom_ribbon layer and instead used ymin and ymax to specify the vertical bounds of the ribbon. This should prevent the warning about unused aesthetics.


Last modified on 2023-09-21