Inclass exercise 0507

尤怡方

2018-05-07

1

dt1<-nlme::Oxboys %>% as.data.frame()
dt1$Subject <- dt1$Subject %>% as.numeric()
attach(dt1)
newdt1 <- dt1[order(-Subject),]

#畫圖,但不知道怎麼按照平均排列
ggplot(newdt1, aes(age,height)) + 
  geom_point(color="#3399FF",shape=1,size=2) + 
  geom_line(color="#3399FF") +
  theme_bw() +
  facet_wrap(~Subject,nrow=5,ncol=6)

2

dt2 <- read.table("C:/Users/user/Dropbox/1062-Data_manage/0507/inclass/income_tw.csv", header=T,sep=",")
dt2 <- dt2 %>% mutate(Count=Count/10000)
attach(dt2)

#畫圖,不知道怎麼排income的順序
ggplot(dt2,aes(Count,Income))+geom_point()+theme_bw()+
  labs(x="Number of person (x 10000)",y="") +
  theme(panel.grid.major.x = element_blank(),
        panel.grid.minor.x = element_blank(),
        panel.grid.major.y = element_line(linetype = "dotted"),
        panel.grid.minor.y = element_line(linetype = "dotted"))

3

Are there gender differences in the three IQ scores?

由下圖可知三種IQ分數沒有性別差異存在

dt3 <- read.table("C:/Users/user/Dropbox/1062-Data_manage/0507/inclass/brainsize.txt", header=T,sep=" ")

dt3 <-dt3 %>% group_by(Gender) %>% summarize(mFS=mean(FSIQ),
                                                 mV=mean(VIQ),
                                                 mP=mean(PIQ),
                                                 sdFS=sd(FSIQ),
                                                 sdV=sd(VIQ),
                                                 sdP=sd(PIQ))
dtmean<-dt3 %>% tidyr::gather(group,mean,mFS:mP) 
dtsd<-dt3 %>% tidyr::gather(group,sd,sdFS:sdP)

dtmean[,-2]<-gsub("m", "", as.matrix(dtmean[,-2]))
dtsd[,-2]<-gsub("sd", "", as.matrix(dtsd[,-2]))

dt3.new<-data.frame(dtmean[1],dtmean[5],dtmean[6],dtsd[6]) 
dt3.new[,3:4]<-as.numeric(unlist(dt3.new[,3:4]))

dt3.new %>% ggplot(.,aes(Gender,mean,color=group))+ 
  geom_point(size=3,position = position_dodge(0.1))+
  theme_bw()+coord_flip()+
  geom_errorbar(aes(ymin=mean-sd,ymax=mean+sd),position = position_dodge(0.1))