Reputation: 433
Surprised not to be able to find this here, I'm guessing this is a common problem.
I'm drawing boxplots in ggplot, plus plotting the data points themselves with geom_point() or geom_jitter(). When I set a size aesthetic for the points, the legend is obscured by dark blobs over the example data points.
library(ggplot2)
d = data.frame(
a = factor(c( rep('a',5), rep('b',5), rep('c',5) )), b = rnorm(15),
c = rnorm(15)
)
ggplot( aes( x = a, y = b, size = c), data = d ) + geom_boxplot(outlier.shape = NA) +
geom_jitter(width = 0.3)
Upvotes: 0
Views: 262
Reputation: 433
Those blobs are coming from the size aesthetic getting applied to geom_boxplot(), leading to legend weirdness. The solution is to apply size aesthetics only to geom_point/jitter().
ggplot( aes( x = a, y = b), data = d ) + geom_boxplot(outlier.shape = NA) +
geom_jitter( aes( size=c ), width = 0.3)
Upvotes: 2