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

geom_segment mitre/bevel with linewidth gradient and color gradient #5349

Closed
aavogt opened this issue Jul 11, 2023 · 2 comments
Closed

geom_segment mitre/bevel with linewidth gradient and color gradient #5349

aavogt opened this issue Jul 11, 2023 · 2 comments
Labels
layers 📈 visual change 👩‍🎨 Rendering change that will affect look of output

Comments

@aavogt
Copy link

aavogt commented Jul 11, 2023

I would like to see these rectangles mitred and also filled with a color gradient. Ideally the aes(linewidth=th) case would also work, in which case each segment is a trapezoid before joining. I'm willing to write the PR. Does the current gradient-less behavior need to be available through something like geom_path(gradient=FALSE)?

ggplot(data.frame(th = seq(0, pi, length.out=12)), aes(sin(th), cos(th), col=th)) + geom_path(linewidth=5) 

image

@teunbrand
Copy link
Collaborator

If you need some kind of interpolation of paths, there already is ggforce::geom_link2() that comes very close to the effect you're looking for. It works best when lineend = 'round'.

library(ggplot2)

ggplot(data.frame(th = seq(0, pi, length.out=12)), aes(sin(th), cos(th), col=th)) + 
  ggforce::geom_link2(aes(linewidth = th), lineend = "round") 

Created on 2023-07-12 with reprex v2.0.2

I'm afraid that it won't be straightforward to implement your proposal without essentially rewriting the paths part of a graphics engine. However if you're interested, Paul Murell has written a series of blogs about variable-width lines:

https://www.stat.auckland.ac.nz/~paul/Reports/VWline/vwline-intro/power-curve.html
https://www.stat.auckland.ac.nz/~paul/Reports/VWline/line-styles/line-styles.html
https://www.stat.auckland.ac.nz/~paul/Reports/VWline/offset-xspline/offset-xspline.html
https://www.stat.auckland.ac.nz/~paul/Reports/VWline/offsetbezier/offsetbezier.html

@teunbrand teunbrand added layers 📈 visual change 👩‍🎨 Rendering change that will affect look of output labels Jul 18, 2023
@teunbrand
Copy link
Collaborator

I'm going to close this as it is a limitation with the graphics system. If anyone finds an elegant solution to this, they're welcome to prepare a PR.

@teunbrand teunbrand closed this as not planned Won't fix, can't repro, duplicate, stale Sep 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
layers 📈 visual change 👩‍🎨 Rendering change that will affect look of output
Projects
None yet
Development

No branches or pull requests

2 participants