當我在 ggplot 中使用尺寸美學時geom_point(),我經常想擴大默認圖例中顯示的值的范圍。例如,在此圖中,有幾個點的值hp遠小于圖例中顯示的最小值 (100),讀者可能難以猜測該值可能是什么:
library(ggplot2)
ggplot(mtcars, aes(x = wt, y = mpg, size = hp))
geom_point()

由
如果您想強調范圍內的差異(同時失去使此類圖更“誠實”的區域比例性),您也可以使用轉換:
sq <- scales::trans_new("squared", function(x) x^2, sqrt)
ggplot(mtcars, aes(x = wt, y = mpg, size = hp))
geom_point(shape = 21, fill = "deepskyblue3")
scale_size_continuous(range = c(0.1, 10),
limits = c(0, 350),
breaks = c(0, 50, 100, 150, 200, 250, 300, 350),
trans = sq)
theme_bw()

轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/436076.html
上一篇:條形圖組相互重疊,而不是相互疊加
