How Can I Plot Confidence Intervals with Dotted Lines?

Viewed 62

I have the following code:

ggplot(pred_grid,
         aes(x = x,
             y = y)) +
    geom_smooth(
      aes(
        ymin = lwr2, ymax = upr2,
        fill = group, colour = group), stat = "identity") +
    theme_gray(base_size = 17) +
    scale_x_continuous(labels = scales::comma) +
    scale_y_continuous(labels = scales::comma)

Chart 1

I then attempted to add dashed lines to signify the confidence intervals using the following code.

ggplot(pred_grid,
       aes(x = x,
           y = y)) +
  geom_smooth(
    aes(
      ymin = lwr2, ymax = upr2,
      fill = brand, colour = brand), stat = "identity") +
  geom_line(aes(y = lwr2), linetype = "dashed") +
  geom_line(aes( y = upr2), linetype = "dashed") +
  theme_gray(base_size = 17) +
  scale_x_continuous(labels = scales::comma) +
  scale_y_continuous(labels = scales::comma)

However, the chart comes back looking like this.

Chart 2

What am I doing wrong?

0 Answers
Related