How to change the color of lines and ribbons in facet_grid

I hope someone can help with this problem of plotting, which I have. Here can be found here .

Basically, I want to build the line (middle) and the associated confidence interval (lower, upper) for the 4 models that I tested. I want the facet to be a Cat_Auth variable, for which there are 4 categories (so 4 graphics). The first โ€œmodelโ€ is actually just an average data sample, and I donโ€™t want the CI for this (the NA values โ€‹โ€‹indicated in the data are not sure if this is the right thing).

I can get the plot in some way:

newdata <- read.csv("data.csv", header=T) ggplot(newdata, aes(x = Affil_Max, y = Mean)) + geom_line(data = newdata, aes(), colour = "blue") + geom_ribbon(data = newdata, alpha = .5, aes(ymin = Lower, ymax = Upper, group = Model, fill = Model)) + facet_grid(.~ Cat_Auth) 

But I would like to use different colored lines and shaded ribbons for each model (for example, the red middle line and the red shaded ribbon for model 2, green for model 3, etc.). In addition, I cannot understand why the blue line corresponding to the first set of means is disconnected as it is.

Would really appreciate any help!

Plot

+5
source share
1 answer

Try the following:

 library(dplyr) library(ggplot2) newdata %>% mutate(Model = as.factor(Model)) %>% ggplot(aes(Affil_Max, Mean)) + geom_line(aes(color = Model, group = Model)) + geom_ribbon(alpha = .5, aes(ymin = Lower, ymax = Upper, group = Model, fill = Model)) + facet_grid(. ~ Cat_Auth) 
+2
source

Source: https://habr.com/ru/post/1268830/


All Articles