EX01

nlme::Oxboys %>%
  mutate(Subject = reorder(Subject, height, mean)) %>%
  xyplot(height ~ age | Subject, data = ., type = c("p", "r","g"))
## Warning: package 'bindrcpp' was built under R version 3.4.3

EX02

dta2 <- read.csv("data/income_tw.csv", header = T)
ggplot(dta2, aes(reorder(Income, Count), Count))+
  geom_point()+
  geom_segment(aes(xend = reorder(Income, Count),y = 0, yend = Count))+
  labs(x = "Income (reorder by Count)")+
  coord_flip()

EX03

3-1

dta3 <- read.table("data/brainsize.txt", header = T)
dta3 %>%
  gather(IQtype, IQvalue, 3:5) %>%
  ggplot(aes(IQtype, IQvalue, color + Gender)) +
  stat_summary(fun.data = mean_se, geom = "pointrange",position = position_dodge(.2)) +
  theme(legend.position = "top")

看起來不同的IQ沒什麼性別差異

3-2

dta3 %>%
  ggplot(aes(Height, Weight)) +
  geom_point(aes(color = Gender)) +
  stat_smooth(aes(color = Gender), method = "lm", se = F) 
## Warning: Removed 2 rows containing non-finite values (stat_smooth).
## Warning: Removed 2 rows containing missing values (geom_point).

在不同性別的層面上,身高與體重的關聯性稍有不同

3-3

dta3 %>% gather(Type, IQ, 3:5) %>% 
  ggplot(aes(IQ, MRICount, color = Gender, group = Gender))+
  geom_point(na.rm = TRUE)+
  stat_smooth(method = "lm", na.rm = TRUE)+
  stat_smooth(aes(group = 1), method = "lm", na.rm = TRUE, se = F, alpha = .5, linetype = "dashed")+
  facet_wrap(~Type)+
  guides(colour = guide_legend(reverse = T))

IQ跟腦容量的關聯性也與性別有交互作用