Closed
Description
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"))
Metadata
Metadata
Assignees
Labels
No labels