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

guide_custom fails to plot gTree grobs #6055

Closed
aravind-j opened this issue Aug 23, 2024 · 1 comment
Closed

guide_custom fails to plot gTree grobs #6055

aravind-j opened this issue Aug 23, 2024 · 1 comment

Comments

@aravind-j
Copy link

When using guide_custom to plot a custom gTree grob as legend, it fails to plot the gTree while the individual component grobs are plotted.

library(ggplot2)
library(grid)


p <- ggplot(mtcars, aes(wt, mpg))


candy <- circleGrob(r = 0.1,
                    x = unit(0.5, units = "npc"),
                    y = unit(0.6, units = "npc"))
stick <- segmentsGrob(x0 = unit(0.5, units = "npc"),
                      x1 = unit(0.5, units = "npc"),
                      y0 = unit(0, units = "npc"),
                      y1 = unit(0.5, units = "npc"))
lollipop <- gTree(children = gList(candy, stick))




p + geom_point(aes(colour = factor(cyl))) +
  guides(custom = guide_custom(lollipop, title = "My lollipop"))

p + geom_point(aes(colour = factor(cyl))) +
  guides(custom = guide_custom(stick, title = "My stick"))

p + geom_point(aes(colour = factor(cyl))) +
  guides(custom = guide_custom(candy, title = "My candy"))

circle_1_1 <- circleGrob(name = "circle_1_1",
                         x = 0.5, y = 0.5, r = 0.1)
circle_1_2 <- circleGrob(name = "circle_1_2",
                         x = 0.5, y = 0.5, r = 0.05,
                         gp = gpar(fill = "red"))
circle_1 <- gTree(name = "circle_1_tree", children = gList(circle_1_1, circle_1_2))



p + geom_point(aes(colour = factor(cyl))) +
  guides(custom = guide_custom(circle_1, title = "My custom"))

p + geom_point(aes(colour = factor(cyl))) +
  guides(custom = guide_custom(circle_1_1, title = "My custom"))

p + geom_point(aes(colour = factor(cyl))) +
  guides(custom = guide_custom(circle_1_2, title = "My custom"))

@teunbrand
Copy link
Collaborator

You can use the width/height arguments to set the size of the lollipop, the only issue here is that there is no size to be determined from the grob itself.

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