如何修改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
相关产品推荐
相关产品推荐

