Advertisements
From the documentation of ggplot2::scale_size_area()
, I read that
scale_size_area()
ensures that a value of 0 is mapped to a size of 0.
However, in this simple example, I still see points where there zeros are. Is this a bug or am I interpreting this wrong?
library(ggplot2)
table(1:3, 1:3) |>
as.data.frame() |>
ggplot() +
aes(x=Var1, y=Var2, size=Freq) +
geom_point() +
scale_size_area()
Data
table(1:3, 1:3) |>
as.data.frame() |>
print()
Var1 Var2 Freq
1 1 1 1
2 2 1 0
3 3 1 0
4 1 2 0
5 2 2 1
6 3 2 0
7 1 3 0
8 2 3 0
9 3 3 1
Result
>Solution :
I think the issue here is that ggplot2 is drawing a point with zero area but non-zero stroke, so it is effectively drawing a tiny circle around nothing.
The shapes in geom_point() typically have both an outline and a fill; shapes 19-25 give you separate control of these, but they all have a stroke parameter to control how heavy the outline appears (if at all).
Compare
ggplot(data.frame(a = 0:5), aes(a, a, size = a)) +
geom_point() +
scale_size_area()
ggplot(data.frame(a = 0:5), aes(a, a, size = a)) +
geom_point(stroke = 0) +
scale_size_area()