![見出し画像](https://assets.st-note.com/production/uploads/images/91135618/rectangle_large_type_2_36f12956248bf598e3ead2c2c0449b7b.jpeg?width=1200)
Rコード データ可視化6
今回はmdsrパッケージのSATを使って、散布図をrで書いてみます。
library(tidyverse)
library(ggplot2)
単純な散布図を書く
g<- ggplot(data = SAT_2010,
aes(x=expenditure,y=math))+geom_point()
plot(g)
![](https://assets.st-note.com/img/1668350337313-8ukvkuB61k.png?width=1200)
次は、散布図の階層わけしたものを使う
SAT_2010 <- SAT_2010 %>% mutate (SAT_rate=cut(sat_pct,breaks=c(0,30,60,100),labels=c("low","medium","high")))
g<-g %+% SAT_2010
g+aes(color=SAT_rate)
![](https://assets.st-note.com/img/1668350388092-jGOEG761Cj.png?width=1200)
lm_sat<- lm(data = SAT_2010, math~expenditure+ SAT_rate)
summary(lm_sat)
anova(lm_sat)
![](https://assets.st-note.com/img/1668350771606-XIa4erJeuc.png?width=1200)
![](https://assets.st-note.com/img/1668351923577-Y7fEbdNuu5.png?width=1200)
lm_sat<- lm(data= SAT_2010,math~expenditure+ SAT_rate + expenditure*SAT_rate)
summary(lm_sat)
anova(lm_sat)
![](https://assets.st-note.com/img/1668351898617-MolapQPRKO.png?width=1200)
![](https://assets.st-note.com/img/1668351950578-PdympSR3j0.png?width=1200)