我有一些数据,其中一个数据是性别,其中性别等于1表示女性,0表示男性。R中的点颜色
假设“reg”是我的线性模型。
当我做plot(studres(reg)~reg$fitted)
它给了我想要的阴谋,但我想它给男性错误涂上蓝色。我确信有一个简单的方法可以做到这一点,但我仍然是R的新手,所以我会很感激任何帮助。
谢谢。
我有一些数据,其中一个数据是性别,其中性别等于1表示女性,0表示男性。R中的点颜色
假设“reg”是我的线性模型。
当我做plot(studres(reg)~reg$fitted)
它给了我想要的阴谋,但我想它给男性错误涂上蓝色。我确信有一个简单的方法可以做到这一点,但我仍然是R的新手,所以我会很感激任何帮助。
谢谢。
plot(reg$fitted, studres(reg), col = dat$gender)
假设数据的形式为:
> dat
y x gender
1 0 0 female
2 10 5 female
3 15 10 male
4 20 15 female
5 24 20 male
6 11 25 male
7 30 30 female
8 34 35 male
使用col
选项。
此外,请尝试?plot
以获得一些工作示例。
set.seed(12)
mydata <- data.frame(
x = rnorm(50),
y = rnorm(50),
male = sample(c(0,1), 50, replace=T)
)
pointCol <- vector()
pointCol[mydata$male==1] <- "blue"
pointCol [MYDATA $雄性== 0] < - “红色”
plot(mydata$x,mydata$y,col=pointCol,pch=16)
legend("topright", pch=16, c("male","female"), col=c("blue", "red"), title =
"Keys")
非常感谢,企鹅。 – N4v
非常感谢Underminer – N4v