首页 > 解决方案 > 如何执行以下任务

问题描述

使用数据集 msleep,针对 bodywt 和 sleep_total 因子绘制 qplot,并使用 geo_smooth 添加一条线。使用 qplot 绘制一条线,应用线性回归模型以消除标准误差。按核心分组。通过 vore 将模型分成多个方面。

qplot(bodywt,sleep_total,data=msleep)+geom_smooth(method="lm")+geom_path(aes(group=vore))+facet_grid(.~vore)

标签: rggplot2

解决方案


你快到了:

library(ggplot2)

qplot(x = bodywt, y = sleep_total, data = msleep) + 
  geom_smooth(method = "lm", formula = y ~ x, se = FALSE) + 
  facet_wrap(facets = vars(vore), nrow = 3, scales = "free_x")

在此处输入图像描述


推荐阅读