Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ggplot2 set geom_point shape with scale_size_binned

I have the following code and would like to know if it is possible to use different shapes in the scale_size_binned command. In my actual data, it is a bit difficult to distinguish between the points so I would like to use different shapes for them. Any suggestions will be appreciated.

rct <- data.frame(

  Effect_Size_Study = rnorm(100),
  F_test_var_stat = runif(100),
  Outcome_Sample_Size = runif(100, min = 6, max = 10000)
)

ggplot(rct, aes(x = Effect_Size_Study, y = F_test_var_stat)) +
  geom_point(aes(size = Outcome_Sample_Size)) +
  scale_size_binned_area(
    limits = c(0, 10000),
    breaks = c(0, 100, 500, 1000, 5000, 10000),
  )
like image 258
Abby Avatar asked Mar 07 '26 04:03

Abby


1 Answers

We can combine the shape and size legend together. This is not much different from the other answer, except the legend.

library(ggplot2)

set.seed(123)
rct <- data.frame(Effect_Size_Study = rnorm(100),
                  F_test_var_stat = runif(100),
                  Outcome_Sample_Size = runif(100, min = 6, max = 10000))

ggplot(rct, aes(x = Effect_Size_Study, y = F_test_var_stat)) +
  geom_point(aes(size = Outcome_Sample_Size, shape = Outcome_Sample_Size)) +
  scale_size_binned_area(name = "Outcome Sample",
                         limits = c(0, 10000),
                         breaks = c(0, 100, 500, 1000, 5000, 10000),
                         labels = c(0, 100, 500, 1000, 5000, 10000)) +
  scale_shape_binned(name = "Outcome Sample", 
                     limits = c(0, 10000),
                     breaks = c(0, 100, 500, 1000, 5000, 10000),
                     labels = c(0, 100, 500, 1000, 5000, 10000))

like image 197
M-- Avatar answered Mar 08 '26 18:03

M--



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!