#設定路徑
setwd("/Users/tayloryen/Desktop/大學/成大課業/大四下/資料管理/0521")
Q1
#讀資料
dta1<-read.table("dta1.txt",header = T)
#查看資料樣式
head(dta1)
## year student_numbers
## 1 1950 3637
## 2 1955 2553
## 3 1960 4564
## 4 1965 6780
## 5 1970 12029
## 6 1975 12250
#繪圖
ggplot(dta1,aes(x=year,y=student_numbers)) + geom_line(lwd = rel(1.2)) +
labs(x="Year",y="Number of students") +
geom_vline(xintercept = c(1990), linetype = "dotted")

Q2
#載入Package
library(leaflet)
## Warning: package 'leaflet' was built under R version 3.4.4
##
## Attaching package: 'leaflet'
## The following object is masked from 'package:mosaic':
##
## evalFormula
#做地圖運算
f_map<-leaflet() %>%
addTiles() %>%
addMarkers(lng = 120.18372, lat = 22.99360, popup = "碳佐麻里")%>%
addMarkers(lng = 120.20133, lat = 22.99444, popup = "台南日式海軍咖哩")%>%
addMarkers(lng = 120.19771, lat = 22.99880, popup = "福州麵館")
f_map
Q3
#載入Package
library(rvest)
## Loading required package: xml2
#The Godfather
fl<-"https://www.imdb.com/title/tt0068646/"
#extract content of web page
film_ts <- read_html(fl)
# extract rating
film_ts %>%
html_node("strong span") %>%
html_text() %>%
as.numeric()
## [1] 9.2
# extract cast
film_ts %>%
html_nodes("#titleCast .itemprop span") %>%
html_text()
## [1] "Marlon Brando" "Al Pacino"
## [3] "James Caan" "Richard S. Castellano"
## [5] "Robert Duvall" "Sterling Hayden"
## [7] "John Marley" "Richard Conte"
## [9] "Al Lettieri" "Diane Keaton"
## [11] "Abe Vigoda" "Talia Shire"
## [13] "Gianni Russo" "John Cazale"
## [15] "Rudy Bond"
The End