Search code examples
rggplot2plotaestheticsmodelsummary

modelsummary modelplot: change linewidth


Consider the following MWE:

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

mod <- lm(bill_length_cm ~ flipper_length_cm + species, data = dat)

modelplot(mod)

which result in

enter image description here

I cannot figure out how to obtain ticker lines ... I have tried various combinations of stroke, size eetc. but without success.

EDIT:

The way to do this in ggplot would be with linewidth argument:

modelplot(mod, draw=FALSE) %>% 
  ggplot(dt, aes(x=term, ymin=estimate-std.error, ymax=estimate+std.error, y=estimate)) +
  geom_pointrange(linewidth=10)

enter image description here

modelplot should pass keyword arguments to geom_pointrange. As written in the examples:

pass arguments to 'geom_pointrange' through the ... ellipsis.

However, the following doesn't work:

modelplot(mod, linewidth=100)

Solution

  • You can change the p$layers[[1]]$geom$default_aes$linewidth parameter directly like

    p <- modelplot(mod)
    p$layers[[1]]$geom$default_aes$linewidth = 1 # set line width up from 0.5
    p
    

    out


    I just looked at the plot object p

    plotobject


    Data

    dat <- read.csv('https://vincentarelbundock.github.io/Rdatasets/csv/palmerpenguins/penguins.csv')
    library(modelsummary)
    dat$bill_length_cm <- dat$bill_length_mm / 10 # rescale mm -> cm
    dat$flipper_length_cm <- dat$flipper_length_mm / 10
    mod <- lm(bill_length_cm ~ flipper_length_cm + species, data = dat)