admin管理员组

文章数量:1277510

I cannot seem to be able to color the lines of different models with different colors in the following model:

library(modelsummary)

url <- '.csv'
dat <- read.csv(url)

# rescale mm -> cm
dat$bill_length_cm <- dat$bill_length_mm / 10
dat$flipper_length_cm <- dat$flipper_length_mm / 10
models <- list(
  "Small model" = lm(bill_length_cm ~ flipper_length_cm, data = dat),
  "Medium model" = lm(bill_length_cm ~ flipper_length_cm + body_mass_g, data = dat),
  "Large model" = lm(bill_length_cm ~ flipper_length_cm + body_mass_g + species, data = dat))

modelplot(models, facet = TRUE)

which results in

I tried with

scale_fill_brewer(palette = "Set1", name = "term")

but doesn't seem to work

I cannot seem to be able to color the lines of different models with different colors in the following model:

library(modelsummary)

url <- 'https://vincentarelbundock.github.io/Rdatasets/csv/palmerpenguins/penguins.csv'
dat <- read.csv(url)

# rescale mm -> cm
dat$bill_length_cm <- dat$bill_length_mm / 10
dat$flipper_length_cm <- dat$flipper_length_mm / 10
models <- list(
  "Small model" = lm(bill_length_cm ~ flipper_length_cm, data = dat),
  "Medium model" = lm(bill_length_cm ~ flipper_length_cm + body_mass_g, data = dat),
  "Large model" = lm(bill_length_cm ~ flipper_length_cm + body_mass_g + species, data = dat))

modelplot(models, facet = TRUE)

which results in

I tried with

scale_fill_brewer(palette = "Set1", name = "term")

but doesn't seem to work

Share Improve this question asked Feb 24 at 20:36 robertspierrerobertspierre 4,4303 gold badges41 silver badges63 bronze badges 0
Add a comment  | 

1 Answer 1

Reset to default 3

You can achieve your desired result by mapping model on the color aes. Afterwards you can set your desired colors using scale_color_brewer or ...

library(modelsummary)
library(ggplot2)

modelplot(models, facet = TRUE) +
  aes(color = model) +
  scale_color_brewer(palette = "Set1")

本文标签: rDifferent colors for different models in faceted modelplotStack Overflow