wilkelab / ggtext

Improved text rendering support for ggplot2
https://wilkelab.org/ggtext/
GNU General Public License v2.0
651 stars 37 forks source link

  not working #51

Closed Andreas-Bio closed 3 years ago

Andreas-Bio commented 3 years ago

  not working

df = mtcars

# Labels with 
labs = c("Within        Budget")

p = ggplot(df, aes(x=hp, y=mpg, color = factor(gear))) +
  geom_point(stat="identity") +
  scale_color_manual(values =c("red","black","green"),
                     aesthetics = "color",
                     labels = labs) +
  theme(legend.position = "bottom",
        legend.text = element_markdown(size=8)
  )
p
clauswilke commented 3 years ago

Yes, I'm aware. If there was an easy way to fix this I'd have done it already. It's eventually going to be addressed by moving to the sinab rendering engine, but realistically that's at least a year out.

Andreas-Bio commented 3 years ago

I found a workaround: labs = c("Within<span> </span><span> </span><span> </span><span> </span>Budget") Maybe you can include that for the meantime in the readme or somewhere else becuase this was not easy to figure out. But maybe I am just slow and there is an easier way. On Google there was nothing though. It's very difficult to add spaces between words.

clauswilke commented 3 years ago

I'll leave this issue open, so people may find your workaround if they search issues.

clauswilke commented 3 years ago

Addressed in #53.

kendavidn commented 2 years ago

I now use this function thanks to @andzandz11

nbsp_func <- function(n){
  paste0(rep("<span> </span>", times = n), collapse = "")
}

nbsp_func(5)
#> [1] "<span> </span><span> </span><span> </span><span> </span><span> </span>"