1、describeBy()、aggregate()
myvar4 <- c("GENDR","RACE","Height")
data4 <- a[myvar4]
library(psych)
attach(data4)
describeBy(Height,list(GENDR=GENDR,RACE=RACE))
means <- aggregate(Height,by=list(GENDR,RACE),FUN=mean,na.rm=TRUE)
detach()
2、barplot()、qqPlot()
#第一种条形图
means$Group.2 <- as.character(means$Group.2)
barplot(x~Group.2+Group.1,means,xlab="GENDR",
col = c("red","yellow","green","blue","black"),
beside=TRUE,ylim=c(0,180),
legend.text=c("RACE1","RACE2","RACE3","RACE4","RACE5"))
#第二种条形图
data4_1 <- subset(data4,GENDR==1)
attach(data4_1)
means_1 <- subset(means,Group.1==1)
barplot(x~Group.2,means_1,xlab="RACE")
detach()
data4_2 <- subset(data4,GENDR==2)
attach(data4_2)
means_2 <- subset(means,Group.1==2)
barplot(x~Group.2,means_2,xlab="RACE")
detach()
install.packages("car")
library(car)
qqPlot(lm(Height~RACE,data=data4_1),simulate=TRUE,main="Q-Q Plot",labels=FALSE)
网友评论