ggplot2默认刻度:图例与极坐标Y轴刻度限值丢失的原因?
极坐标下ggplot2刻度限值丢失问题溯源
这是《How does ggplot calculate its default breaks?》(ggplot如何计算默认刻度?)的后续问题,源于寻找《How to add y-axis labels inside coord_polar graph ggplot?》(如何在ggplot极坐标图内添加Y轴标签?)更优雅解决方案的过程。研究发现ggplot2始终使用scales::extended_breaks()计算默认刻度,但在极坐标模式下,Y轴以及连续数据图例的刻度限值会出现丢失,请问这一现象具体发生在哪个环节?
示例代码
library(ggplot2) ggplot(mtcars, aes(x = mpg, y = mpg, size = hp)) + geom_point() + coord_polar() + labs(color = 'am')
对比结果
scales::extended_breaks()(mtcars$mpg) #> [1] 10 15 20 25 30 35 scales::extended_breaks()(mtcars$hp) #> [1] 50 100 150 200 250 300 350
(创建于2023-04-01,使用reprex v2.0.2)
内容的提问来源于stack exchange,提问作者tjebo
相关产品推荐
相关产品推荐

