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

如何调整ggplot绘制的散点图上R²值的字体大小?

你代码中R²字号不生效的核心原因是将size参数写在了aes()美学映射内部,该位置的参数是用于关联数据变量的,无法直接指定固定字号。你只需要将size参数移出aes(),作为stat_regline_equation()的直接入参即可调整R²文本的大小,同时你的代码里stat_smooth的参数存在拼写错误,sixe需要修正为size。

修改后的完整代码如下:

ggplot(Gully, aes(x = Downstream, y = Depth))+
  geom_point(size = 0.5)+
  stat_smooth(method= "lm", col = "black", size = 0.5) + 
  theme_bw()+
  theme_classic()+
  stat_regline_equation(label.y = -7, aes(label = ..rr.label..), size = 3)+
  labs(y = "Decline in waterhole depth (m)", x = "Downstream distance (km)")+
  theme(text=element_text(size=8, family = "Arial")) 

你可以按需调整size参数的数值,数值越小R²文本字号越小。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.03 12:48:04