strengejacke / sjPlot

sjPlot - Data Visualization for Statistics in Social Science
https://strengejacke.github.io/sjPlot
603 stars 91 forks source link

sjPlot_theme enhancement - synchronize font family across plot labels and data labels #854

Open coverton-usgs opened 1 year ago

coverton-usgs commented 1 year ago

I don't know if this is more of a ggplot issue or a sjPlot enhancement. It currently is very difficult to apply uniform font changes across all aspects of a plot. for instance:

a = plot_model(my_random_model,
  show.values = TRUE,
  title = c("something important"),
  axis.title = c("more details"))

windowsFonts(A = windowsFont("Times New Roman"))

a + theme_sjplot(base_family = "A")

Will show a plot with Times New Roman font for the title, axis headings and labels. But the data values in the center of the plot will remain the default font.

In order to obtain data labels in the correct font, I would need to hide values in the plot_model statement and add them using a custom geom_plot

aa = plot_model(my_random_model,
  show.values = FALSE,
  title = c("something important"),
  axis.title = c("more details"))

windowsFonts(A = windowsFont("Times New Roman"))

aa + theme_sjplot(base_family = "A") + geom_text(aes(label( round(my_random_model@beta,2)), family = "A", nudge_x = 0.25, check_overlap = F)

Perhaps this is something that could be modified in the plot_model object when using theme_sjplot?; i.e.,

> a$layers[[4]]
mapping: label = ~p.label 
geom_text: parse = FALSE, check_overlap = FALSE, na.rm = FALSE ###  <- added here
stat_identity: na.rm = FALSE
position_nudge