打印的數字的實際大小由scale_size_continuous
控制。該比例採用參數range
,該參數定義了用於最小和最大對象的尺寸。默認情況下,range = c(1,6)
。你可以用這兩個數字來玩,直到你得到所需的結果。
默認值:
ggplot(mtcars, aes(carb)) +
stat_count(aes(y = ..count..),
show.legend = F, geom = "text") +
element_text(aes(size = ..count.., label = ..count..)) +
scale_size_continuous(range = c(1, 6))

放大小的數字,但保持最大尺寸相同:
ggplot(mtcars, aes(carb)) +
stat_count(aes(y = ..count..),
show.legend = F, geom = "text") +
element_text(aes(size = ..count.., label = ..count..)) +
scale_size_continuous(range = c(3, 6))

放大所有數字:
ggplot(mtcars, aes(carb)) +
stat_count(aes(y = ..count..),
show.legend = F, geom = "text") +
element_text(aes(size = ..count.., label = ..count..)) +
scale_size_continuous(range = c(4, 12))
