ggplot2: how to produce smaller points

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



ggplot2: how to produce smaller points



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.:


size


size


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


size


cex


plot(df$c2 ~ df$c1, cex = c(1, 0.1, 0.01))





I don't understand your question. Have you run the code in your question? The ggplot code produces 3 points of different sizes. If you want even smaller points, use even smaller numbers. If you run the plot code in your question, it also produces points of different sizes, but not quite the same as the ggplot code... So whether or not size "matches" cex depends on what you mean by "match" - they work more or less the same but don't produce identical results.
– Gregor
Aug 6 at 3:26



ggplot


plot


ggplot


size


cex





Hi @Gregor, thanks. The size (diameter) of the points is not proportional to the size value as you can see with the last two points.
– ed_sans
Aug 6 at 3:52





Possible duplicate of Changing size of proportional dots in ggplot map
– MLavoie
Aug 6 at 9:36





That's a lot clearer - I'd recommend editing your question to make it state the aspects you actually want help with.
– Gregor
Aug 6 at 11:53




2 Answers
2



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



There is a size = argument to geom_point, but you either specify a size for all points:


size =


geom_point


+ geom_point(size = 0.5)



Or you map the size to one of the columns in your data using aes:


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:


scale_size_continuous


+ geom_point(aes(size = c2)) + scale_size_continuous(range = c(2, 8))


cex






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

make 2 or more post in bootsrap

Store custom data using WC_Cart add_to_cart() method in Woocommerce 3

Firebase Auth - with Email and Password - Check user already registered