Home > front end >  Constant label size with geom_point() while using variable point size
Constant label size with geom_point() while using variable point size

Time:07-07

I have generated a scatterplot with variable point size using geom_point(). I also wish to label the points, but doing so also adjusts the size of the label. Is it possible to keep a constant label size while varying the point size?

See example code and output below. I want basically this output except with a single consistent label font size.

library(ggplot2)
library(magrittr)

df = data.frame(score1 = rnorm(10),
               score2 = rnorm(10),
               group_size = exp(rnorm(10)),
               group_name = LETTERS[1:10]
)

df %>% ggplot(aes(x = score1, y = score2, size = group_size, label = group_name))  
  geom_point()  
  geom_text(vjust = 1.8)

enter image description here

CodePudding user response:

Move the size aesthetic to geom_point():

ggplot(df, aes(x = score1, y = score2, label = group_name))  
  geom_point(aes(size = group_size))  
  geom_text(vjust = 1.8)
  • Related