library(tibble)
df <- tibble(x = 2, y = 15, grob = list(grid::circleGrob(r = 0.2)))
# without nudging no segments are drawn
ggplot(data = mtcars,
aes(wt, mpg)) +
geom_point(aes(colour = factor(cyl))) +
geom_grob(data = df,
aes(x, y, label = grob))
# with nudging segments are drawn
ggplot(data = mtcars,
aes(wt, mpg)) +
geom_point(aes(colour = factor(cyl))) +
geom_grob(data = df,
aes(x, y, label = grob),
nudge_x = 0.5,
colour = "red",
hjust = 0.5,
vjust = 0.5)
ggplot(data = mtcars,
aes(wt, mpg)) +
geom_point(aes(colour = factor(cyl))) +
geom_grob(data = df,
aes(x, y, label = grob),
nudge_x = 0.5,
colour = "red",
colour.target = "none",
hjust = 0.5,
vjust = 0.5)
# with nudging plotting of segments can be disabled
ggplot(data = mtcars,
aes(wt, mpg)) +
geom_point(aes(colour = factor(cyl))) +
geom_grob(data = df,
aes(x, y, label = grob),
add.segments = FALSE,
nudge_x = 0.5,
hjust = 0.5,
vjust = 0.5)
Run the code above in your browser using DataLab