jacob-long / jtools

Tools for summarizing/visualizing regressions and other helpful stuff
https://jtools.jacob-long.com
GNU General Public License v3.0
162 stars 22 forks source link

Adding the ability to influence linewidth to plot_coefs/plot_summs #130

Closed kingquote closed 1 year ago

kingquote commented 1 year ago

I wanted to include a plot_summs output in a paper and was unhappy with how thin the CI lines were. I therefore added custom functions to my code that are based on your plot_summs and plot_coefs. I'm only a novice programmer busy with other things, so I don't really have the skill or time to adapt my changes to all possible types of plots (eg I only worked without distributions) or to properly test them, but I still thought I should let you know what I did, maybe as a starting point if you want to implement this feature at some point.

I simply passed a new argument called line.width to ggplot in the same way as point.size, though I multiply line.width with 0.8 to make sure an input of 1 gets the same thickness as the current default. Then I changed fatten and size in the following section, and added the guides() line to undo the fattening in the legend

line.width <- line.width * 0.8

 # If there are overlapping distributions, the overlapping pointranges
  # are confusing and look bad. If plotting distributions with more than one
  # model, just plot the points with no ranges.
  if (plot.distributions == FALSE || n_models == 1) {
    # Plot the pointranges
    p <- p + ggstance::geom_pointrangeh(
      aes(y = term, x = estimate, xmin = conf.low,
          xmax = conf.high, colour = model, shape = model),
      position = ggstance::position_dodgev(height = dh),
      fill = "white", fatten = point.size / line.width, size = line.width,
      show.legend = length(mods) > 1) + # omit legend if just a single model
      guides(colour = guide_legend(override.aes = list(size = point.size/4)))
  } else {
    p <- p + geom_point(
      aes(y = term, x = estimate, colour = model, shape = model),
      fill = "white", size = point.size, stroke = 1, show.legend = TRUE)
  }

Hope it can be of some use :)

jacob-long commented 1 year ago

Thanks for the suggestion! Will be included in the next release via the argument line.size.