Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FR] Support shadowtext / text background #58

Closed
albert-ying opened this issue Jan 15, 2022 · 3 comments
Closed

[FR] Support shadowtext / text background #58

albert-ying opened this issue Jan 15, 2022 · 3 comments

Comments

@albert-ying
Copy link

albert-ying commented Jan 15, 2022

There are currently multiple implementations for the geom_text with border. For example, shadowtext. ggrepel also take a bg.color argument that can produce a similar effect.

https://guangchuangyu.github.io/2017/11/shadow-text-effect-in-grid-and-ggplot2-graphics/
https://stackoverflow.com/questions/56798482/how-to-combine-repelling-labels-and-shadow-or-halo-text-in-ggplot2

This could be helpful for geomtextpath, especially when gap = FALSE, or when plot with other geom layers.

Also could help my previous problem #55 , to better separate the text and line when vjust is not working.

Thank you so much!

gZCst

@teunbrand
Copy link
Collaborator

teunbrand commented Jan 15, 2022

I like the idea, but I don't think it makes sense for us to implement as {ggfx} can do this (and more) without us having to lift a finger.

library(ggfx)
#> Warning: package 'ggfx' was built under R version 4.1.1
library(geomtextpath)
#> Loading required package: ggplot2

t <- seq(5, -1, length.out = 1000) * pi

spiral <- data.frame(x    = sin(t) * 1:1000, 
                     y    = cos(t) * 1:1000,
                     text = paste("Like a circle in a spiral,",
                                  "like a wheel within a wheel,",
                                  "never ending or beginning,",
                                  "on an ever spinning reel")
)

ggplot(spiral, aes(x, y, label = text)) +
  with_outer_glow(
    geom_textpath(size = 7, vjust = 2, text_only = TRUE, colour = "white"),
    sigma = 0, expand = 2
  ) +
  coord_equal(xlim = c(-1500, 1500), ylim = c(-1500, 1500))

Created on 2022-01-15 by the reprex package (v2.0.1)

@teunbrand
Copy link
Collaborator

teunbrand commented Jan 15, 2022

A small note: once R4.2.0 comes out, it might make sense to do outlined text as it becomes part of the grid package. See https://www.stat.auckland.ac.nz/~paul/Reports/GraphicsEngine/paths/paths.html, 2nd paragraph, 4th example

@albert-ying
Copy link
Author

Wow thank you so much! I didn't know that the ggfx can work here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants