r - 使用 ggplot 绘制线并拟合线性回归线
问题描述
我生成了一个玩具数据,如下所示:
toy.df <- data.frame(ID = rep(paste("S",1:25, sep = "_") ,4) , x = rep(seq(1,5), 20), y = rnorm(100), color_code = rnorm(100)
,group = rep(letters[1:4] , 25) )
我想使用 ggplot 生成多条线以及 4 个方面中的点,并将线性回归线拟合到每个方面中的每组线。
toy.df %>% ggplot(aes(x = x, y = y, group = ID)) +
facet_wrap( . ~ group, scales = 'free', ncol = 2)+
geom_point() +
geom_line(aes(color = color_code)) +
geom_smooth(method = 'lm')
但它不会在 x 轴(1 到 5)上生成线条
你知道我该如何解决这个问题吗?
解决方案
推荐阅读
- flutter - 用@freezed 装饰的类不能有可变属性
- java - 如何配置 AWS 用户 cognito 身份验证流程以在 Java sdk 后端生成身份令牌、访问令牌?
- javascript - 选择具有匹配数据属性的最近元素
- shell - 将具有多个名称-多值对的文件转换为 Rows shell 脚本
- xml - 使用 XSLT 显示所有元素的元素 repititions 之间的 Subtotolas
- php - Laravel 7浏览器不下载文件
- arrays - 将特定值移动到随机填充数组的末尾
- asp.net-core - 为托管的 blazor 实现进度条
- c++ - 字符串文字中换行符的换行计数器 [更新]
- reactjs - React/redux combineReducers 问题