larmarange / ggstats

Extension to ggplot2 for plotting stats
https://larmarange.github.io/ggstats/
GNU General Public License v3.0
26 stars 1 forks source link

Italic on ggcoef_table #54

Closed Ikarobarreto closed 5 months ago

Ikarobarreto commented 5 months ago

Hey everyone,

I've been using the ggcoef_table function, and I've been asked to italicize partially variable names within it. I've tried a couple of methods like HTML and expressions, but I haven't had any luck. Could someone please assist me? I've provided a reprex below. My aim is to italicize just the word "Variable."

library(ggstats) dat<-data.frame(x=rnorm(100),y=rnorm(100),w=runif(100),z=runif(100)) mod<-lm(x~y+w+z) ggcoef_table(mod,colour = NULL,add_reference_rows = F, variable_labels = list(y= "Variable Y", w = "Variable W", z = "Variable Z"))

Thanks!

larmarange commented 5 months ago

The easiest way would be to use markdown with the ggtext package.

library(ggplot2)
library(ggstats)
dat <- data.frame(x = rnorm(100), y = rnorm(100), w = runif(100), z = runif(100))
mod <- lm(x ~ y + w + z, data = dat)

p <- ggcoef_model(
  mod,
  colour = NULL, add_reference_rows = F,
  variable_labels = list(
    y = "*Variable* Y",
    w = "W: **bold** and *italic*",
    z = "*Variable* Z"
  )
)

p


library(ggtext)
p + theme(strip.text.y.left = element_markdown())

p + theme(strip.text.y.left = element_markdown(face = "plain"))


pt <- ggcoef_table(
  mod,
  colour = NULL, add_reference_rows = F,
  variable_labels = list(
    y = "*Variable* Y",
    w = "W: **bold** and *italic*",
    z = "*Variable* Z"
  )
)

pt


pt[[1]] <- pt[[1]] + theme(strip.text.y.left = element_markdown())
pt

Created on 2024-02-26 with reprex v2.0.2