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

如何修改stat_poly_eq生成的回归方程小数点标记为逗号?

解决stat_poly_eq回归方程小数点转逗号的问题

要把回归方程里的小数点换成逗号,直接在stat_poly_eq()中添加format.args = list(decimal.mark = ",")参数即可,该参数会控制系数和R²值的小数点显示格式。

修改后的完整代码如下:

data(mpg)

ggplot(mpg, aes(y = displ, x = hwy)) +
  geom_point(alpha = 0.5, color = "cadetblue") +
  geom_smooth(method = "lm", se = F, color = "black", size = 0.5) +
  stat_poly_eq(aes(label = paste(after_stat(eq.label),
                                 after_stat(rr.label),
                                 sep = "*plain(\",\")~~")),
               coef.digits = 3,
               format.args = list(decimal.mark = ","))

原理:stat_poly_eq()内部通过格式化函数处理数值,format.args参数会将小数点替换规则传递给这些函数,实现标点符号的替换。

内容的提问来源于stack exchange,提问作者Fernanda Peres

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.08 05:45:40