You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.26 15:42:35