Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从R中的线性模型创建散点图_R_Ggplot2_Linear Regression - Fatal编程技术网

从R中的线性模型创建散点图

从R中的线性模型创建散点图,r,ggplot2,linear-regression,R,Ggplot2,Linear Regression,我想画一个散点图。我正在使用儿童攻击性数据创建一个线性模型,首先包含所有预测变量 # install.packages(c("profandyfield", "tidyverse"), dependencies = TRUE) library(tidyverse) cha <- read_csv('https://www.discovr.rocks/csv/child_aggression.csv') 但是给我的错误是: Error: Aesth

我想画一个散点图。我正在使用
儿童攻击性
数据创建一个线性模型,首先包含所有预测变量

# install.packages(c("profandyfield", "tidyverse"), dependencies = TRUE) 
library(tidyverse)
cha <- read_csv('https://www.discovr.rocks/csv/child_aggression.csv')
但是给我的错误是:

Error: Aesthetics must be either length 1 or the same as the data (3330): x
不知道我错过了什么

augmented_model <- augment(m2$fit, cha)
augmented_model
augmented_model %>%
  pivot_longer(cols = tv:parenting_style) %>%
  ggplot(aes(m2$fit, y = aggression)) +
  geom_point(aes(color = .cooksd), alpha = 0.5) +
  facet_wrap(~ cols, scales = "free_x") +
  scale_color_viridis_c(option = "inferno", direction = -1)
Error: Aesthetics must be either length 1 or the same as the data (3330): x
> dput(head(cha))
structure(list(aggression = c(0.374160430640457, 0.771153401696602, 
-0.0977275767529503, 0.0159353083172345, -0.275384590127613, 
0.157853298602792), tv = c(0.172670536041966, -0.0328718424282237, 
-0.0744602054947211, -0.00442663143025586, -0.675238689863032, 
0.202480135088309), video_games = c(0.141906686312197, 0.70991822158973, 
-0.390140556361705, -0.408080359578329, -0.277777805092463, 0.321508290608204
), sibling_aggression = c(-0.328216369799206, 0.576836666584888, 
-0.217184051790135, 0.0462232544752437, -0.891045376926662, -0.153712620137455
), diet = c(-0.110302848529567, -0.0229902994363559, 0.280300500733838, 
-0.263479227693543, 0.226581391463754, -0.36863818544968), parenting_style = c(-0.27903391265838, 
-1.24816654381935, -0.328062974471144, -1.00511930778355, 0.489477816099021, 
-1.74098228316479)), row.names = c(NA, -6L), class = c("tbl_df", 
"tbl", "data.frame"))