讀取資料、新增變項

dta <- read.table("birth_college.txt",header = T)
dta$Year <- 1981:2009
dta$College <- dta$Entrance-40
tail(dta)
##    Birth Entrance Year College
## 24   9.6       87 2004      47
## 25   9.1       89 2005      49
## 26   9.0       91 2006      51
## 27   8.9       96 2007      56
## 28   8.6       97 2008      57
## 29   8.3       97 2009      57

繪圖

p <- ggplot() +
  geom_point(data=dta,aes(Year,Birth),pch=1)+
  scale_y_continuous(
    name=expression("Birth rate(0.1%)"),limits=c(0,60),breaks = seq(0,60,10),
                     sec.axis = sec_axis(~.+40,breaks = seq(40,100,10),name="Acceptance rate(%)"))+
  geom_point(data=dta,aes(Year,College))+
  theme(legend.position = 'topleft')+
  theme(legend.background = element_rect(fill = 'white', colour = 'black'))

p + theme_bw()
## Warning: Removed 13 rows containing missing values (geom_point).