1

I have a data set (a small excerpt below) that is plotting three lines - two estimated from one model with confidence intervals and a third line that serves as an external confirmation of the results.

bestFit <- data.frame(Year = c(2006, 2007, 2008,
                               2006, 2007, 2008,
                               2006, 2007, 2008),
                      Estimate = c(4208, 4570, 4925,
                                   0872, 1324, 1193,
                                   6009, 5705, 6474),
                      Lo95CI = c(2903, 3561, 4036,
                                 0693, 1113, 0999,
                                   NA,   NA,   NA),
                      Hi95CI = c(5209, 5453, 5725,
                                 0998, 1489, 1330,
                                   NA,   NA,   NA),
                      Reconstruction = c("Abun", "Abun", "Abun",
                                         "Recr", "Recr", "Recr",
                                         "Extl", "Extl", "Extl"))
bestFit$Reconstruction <- factor(bestFit$Reconstruction, ordered = TRUE,
                         levels = c("Abun", "Recr", "Extl"))

ggplot(aes(y = Estimate, x = Year, fill = Reconstruction), data = bestFit) + 
    geom_ribbon(aes(ymin = Lo95CI, ymax = Hi95CI, 
                    fill = Reconstruction), alpha = 0.25) +
    geom_point(aes(colour = Reconstruction)) + 
    geom_path(aes(colour = Reconstruction), size = 1) +
    scale_x_continuous(breaks = seq(2006, 2008, 2)) +
    scale_fill_manual(values = c("#F8766D", "#00BA38", "#619CFF")) + 
    scale_color_manual(values = c("#F8766D", "#00BA38", "#619CFF")) +
    scale_linetype_manual(values = c("solid", "solid", "dotted"))

enter image description here

I can manually set the colors, but am having trouble manually setting the line type. I want the first two lines (which are from my model) to be solid and the third line (which is from an external model) dashed.

3
  • 4
    You haven't mapped the linetype aesthetic. Add linetype = Reconstruction inside the aes portion of your geom_path call Commented Jun 30, 2022 at 16:10
  • 1
    Dammit @AllanCameron, you're just too quick! Commented Jun 30, 2022 at 16:11
  • I could have sworn that I had tried that and it didn't work... but it works now, so thanks a bunch! Commented Jun 30, 2022 at 16:30

1 Answer 1

1

From comments:

You haven't mapped the linetype aesthetic. Add linetype = Reconstruction inside the aes portion of your geom_path call.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.