Reputation: 312
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)
Upvotes: 2
Views: 230
Reputation: 33498
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)
Upvotes: 4