Reputation: 93
If I want to jitter points, but my x axis has uneven intervals like this:
library(ggplot2)
ggplot(ToothGrowth, aes(x=dose, y=len)) + geom_point()
how can I vary the widths of the jitter at different x axis values so I don't end up with overlap like this?
ggplot(ToothGrowth, aes(x=dose, y=len)) + geom_jitter(width = 0.3,size = 4)
I want a way for instance to make the jitter narrow at 0.5, wider at 1, and widest at 2.
Upvotes: 0
Views: 241
Reputation: 1076
A dirty way might be to jitter the dose before the plotting:
JitterSize <- rep(c(1.5, 3, 6), table(ToothGrowth$dose))
ToothGrowth $ Jitter <- jitter(ToothGrowth $ dose, JitterSize)
ggplot(data = ToothGrowth,
aes(x = Jitter, y=len, color = as.character(dose))) +
geom_point(size = 4)
Updated based on abruh's comments.
Upvotes: 1