我使用 geom_point() 生成了具有可变点大小的散点图。我也希望标记这些点,但这样做也会调整标签的大小。是否可以在改变点大小的同时保持恒定的标签大小?
请参阅下面的示例代码和输出。我基本上想要这个输出,除了单一一致的标签字体大小。
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)
最佳答案
将尺寸美学移至geom_point()
:
ggplot(df, aes(x = score1, y = score2, label = group_name)) +
geom_point(aes(size = group_size)) +
geom_text(vjust = 1.8)
关于r - 使用 geom_point() 恒定标签大小,同时使用可变点大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72899214/