Reputation: 123
This question is related to this post, but distinct.
Instead of using alpha, or color or shape, I would like to use something akin to ggrepel
. Instead of text labels, the points would be moved away from their original location, and an arrow or line segment would point to the original location of the point.
For example, in this plot from @Claus-Wilke :
ggplot(mpg, aes(displ, cty, colour = drv, fill = drv)) +
geom_point(position=position_jitter(h=0.1, w=0.1),
shape = 21, alpha = 0.5, size = 3) +
scale_color_manual(values=linecolors) +
scale_fill_manual(values=fillcolors) +
theme_bw()
Instead of jittering, overlapping points would be repelled from each other, and arrows/segments would start at the point, and end at the point's original location. This would get very busy with a lot of overlaps, but would be bearable if there were only a few. Any suggestions?
Thanks!
Upvotes: 0
Views: 277
Reputation: 17069
This is the closest I could get using ggrepel::geom_label_repel()
, though I don't think the result is a useful visualization and wouldn't use it myself.
library(ggplot2)
library(ggrepel)
linecolors <- c("#714C02", "#01587A", "#024E37")
fillcolors <- c("#9D6C06", "#077DAA", "#026D4E")
ggplot(mpg, aes(displ, cty, colour = drv, fill = drv)) +
geom_label_repel(
aes(label = " "),
size = 0.35,
label.r = 0.25,
alpha = 0.5,
max.overlaps = Inf,
min.segment.length = 0,
force = 5,
seed = 13
) +
scale_color_manual(values=linecolors) +
scale_fill_manual(values=fillcolors) +
coord_cartesian(xlim = c(0, 8), ylim = c(0, 40)) +
theme_bw()
Upvotes: 2