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

chunky resolution of circular tree segments #614

Open
ulo opened this issue May 23, 2024 · 0 comments
Open

chunky resolution of circular tree segments #614

ulo opened this issue May 23, 2024 · 0 comments

Comments

@ulo
Copy link

ulo commented May 23, 2024

Hi!
I love to use the circular ggtree layouts, but always found the low line segment resolution - especially close to the root - somewhat unattractive:

image

Apparently that is a gneral issue with ggplot polar plots:
https://stackoverflow.com/questions/9483033/increase-polygonal-resolution-of-ggplot-polar-plots

Following the stackoverflow post from above, overwriting the ggplot2:::coord_munch function solves the issue:

# Save the original version of coord_munch
coord_munch_old <- ggplot2:::coord_munch

# Make a wrapper function that has a different default for segment_length
coord_munch_new <- function(coord, data, range, segment_length = 1/500, is_closed = FALSE) {
  coord_munch_old(coord, data, range, segment_length, is_closed)
}
# Make the new function run in the same environment
environment(coord_munch_new) <- environment(ggplot2:::coord_munch)

# Replace ggplot2:::coord_munch with coord_munch_new
assignInNamespace("coord_munch", coord_munch_new, ns="ggplot2")

This results in much nicer line segments:

image

Maybe you could implement this somehow in your great library?

Also, if I understood the stackoverflow discussion correctly, then the low resolution would be less of an issue if the numerical range of x-values would be higher (which is only between 0 and 0.5 in my circular trees). Maybe increasing this scale is an easier solution compared to overwriting some ggplot2 function?

Cheers,
Ulrich

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

1 participant