jacob-long / jtools

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

Alter y-axis #137

Closed oalavijeh closed 1 year ago

oalavijeh commented 1 year ago

Thanks for the amazing tool!

Is it possible to change the units of the x-axis. I am plotting the results of a GLM and the prevalence of a disease in a case/control cohort. The y-axis is 0.010-0.020 but I would like to output it as 0-2%. Is that possible?

Many thanks

jacob-long commented 1 year ago

Assuming you're trying to format the output of effect_plot(), you will need to use ggplot2's tools for doing this. Here's an example:

library(jtools)
library(ggplot2)
fit <- lm(Income ~ Frost + Illiteracy + Murder, data = as.data.frame(state.x77))
effect_plot(fit, Frost) + 
  scale_y_continuous(labels = scales::percent)

The example above is a little nonsensical since the y-axis shouldn't be a percentage, but you get the idea. The main point is if you add the + scale_y_continuous(labels = scales::percent), you'll get the y-axis labels expressed as percentages.

oalavijeh commented 1 year ago

Many thanks