Reputation: 3514
I have a large dataset that I am plotting using a scatter plot. These points have a unique combination of x,y and therefore they don't overlap, but some of them are very close to each other therefore I'm plotitng them with small size.
1- How to produce smaller point symbols (smaller size
) so that the areas are proportional. In this example, the last point does not have an area proportional to the size
. I was expecting it 10 smaller than the middle one e.g.:
df <- data.frame(c1 = 1:3, c2 = c(1,1,1))
ggplot(df) + geom_point(aes(x= c1, y = c2), size = c(1, 0.1, 0.01))
2- How does the size
in ggplot2 matches the R graphics cex
argument e.g.: plot(df$c2 ~ df$c1, cex = c(1, 0.1, 0.01))
.
Thanks
Upvotes: 4
Views: 11404
Reputation: 31
Aparently you can get to zero minimum dot sizes, by changing the parameter "stroke" to stoke = 0
. Found this solution at this blog post. Works perfect for me!
Upvotes: 0
Reputation: 145
The issue here might be that a point in ggplot
consists of an interior and a border part (for lack of better wording). The interior is controlled with fill
, alpha
, and size
, and the border with color
and stroke
. With size
, you will, therefore, only change the size of the interior, while the line thickness of the border will remain unchanged. Try setting stroke = 0
and see how that changes your point size in case of smaller values.
Upvotes: 1
Reputation: 33782
There is a size =
argument to geom_point
, but you either specify a size for all points:
+ geom_point(size = 0.5)
Or you map the size to one of the columns in your data using aes
:
+ geom_point(aes(size = c2))
In the latter case, you can control the range of sizes using scale_size_continuous
. The default is min = 1, max = 6. To get e.g. min = 2, max = 8:
+ geom_point(aes(size = c2)) + scale_size_continuous(range = c(2, 8))
cex
Upvotes: 10
Reputation: 310
You can try
geom_point(shape = ".")
this will make the point 1 pixel in size.
This is from page 70 of ggplot2 second edition by H Wickham
Upvotes: 12