Q1
#centered age, intercept equals to individual mean
dta <- Oxboys %>% mutate(Subject = reorder(Subject, height, mean))
# sequence by intercept
xyplot(height ~ age | Subject, data = dta,
grid = TRUE,
type = c("p", "smooth"), lwd = 1,
xlab = "Age (centered)", ylab = "Height (cm)")

Q2
dta2 <- read.csv("income_tw.csv", h = T)
ggplot(dta2, aes(Count/10000, ordered(Income, levels = Income))) +
geom_point() +
geom_segment(aes(x = 0, xend = Count/10000, yend = ordered(Income, levels = Income))) +
labs(x= "Number of persons(x10,000)", y = "Income", title = "Distribution of personal disposable income in Taiwan in 2015")

Q3
dta3 <- read.table("brainsize.txt", h = T) %>% gather(IQs, score, 3:5)
#1 Are there gender differences in the three IQ scores?
ggplot(dta3, aes(IQs, score, color = Gender)) +
stat_summary(fun.data = mean_se, geom = "pointrange", position = position_dodge(0.2))

#2 Is the relationship between height and weight gender dependent?
ggplot(dta3, aes(Height, Weight, color = Gender)) +
geom_point() +
stat_smooth(method = "lm", size = rel(1.1), se = F) +
theme_bw()

#3 Is the relationship between IQ and brainsize (as measured by MRIcount) gender dependent?
ggplot(dta3, aes(score, MRICount, color = Gender)) +
geom_point() +
stat_smooth(method = "lm", size = rel(1.1), se = F) +
facet_wrap(~IQs) +
theme_bw()
