Home > Net >  Is there a way to change the 'divisions' of size in a ggplot scatterplot?
Is there a way to change the 'divisions' of size in a ggplot scatterplot?

Time:10-28

Basically I am using a variable on my dataset to alter the size of the data points of my plot. When I use this variable R automatically uses 3 division: 100,000 200,000 300,000. Nevertheless the majority of my data has a variable less than 100,000 and the row that has 300,000 as a value, makes jumps between size too large making the graph not show accurate information.

Is there a way to define the number of divisions of size. What I have tried is changing the scale with the following code:

scale_size_continuous(range = c(5,10))

This just modifies the size of all dots, I do not want to change the scale, but I want to do is introduce more sizes. Is there any way I can manually modify this parameter.

CodePudding user response:

If you want more 'points' you need more breaks, e.g.

library(tidyverse)

df <- mtcars

df %>%
  ggplot(aes(x = cyl, y = disp, size = disp))  
  geom_point()  
  scale_size_continuous(range = c(1,10))

                        
df %>%
  ggplot(aes(x = cyl, y = disp, size = disp))  
  geom_point()  
  scale_size_continuous(range = c(1,10),
                        breaks = seq(50, 500, 50))

Created on 2022-10-28 by the reprex package (v2.0.1)

Does that solve your problem?

  • Related