5.Plot places in administratice areas of Taiwan you have visited so far.
library(choroplethrAdmin1)
## Warning: package 'choroplethrAdmin1' was built under R version 3.2.5
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 3.2.5
taiwanm <- get_admin1_map("taiwan")
taiwanm$visit <- ifelse(taiwanm$region %in% c("kao-hsiung hsien","pingtung","tainan","hsinchu","yilan",
"keelung","t'ai-pei shih","taipei","chiayi","hualien" ,
"nantou","taitung","miaoli","yunlin"), 1 , 0)
ggplot(taiwanm, aes(long, lat, group = group)) +
geom_polygon(aes(fill = as.factor(visit)), color = "gray") +
scale_fill_manual(values=c("white","green"),name="Visited",labels=c("No","Yes")) +
theme_minimal()
Dates & Times 1.Assume that your total life span is 100 years. Find out how often your birthday falls on each day of the week.
table(weekdays(seq(as.Date("1994-10-22"), by = "1 years", length = 100)))
##
## 星期一 星期二 星期三 星期五 星期六 星期日 星期四
## 14 14 15 14 14 15 14
2.Reproduce the plot of calls for police assistances around 24 hours in New York City
library(ggplot2)
dta<-read.csv("calls_nyc.csv",h=T)
head(dta)
## Hour Calls
## 1 0.5 1080
## 2 1.5 910
## 3 2.5 770
## 4 3.5 780
## 5 4.5 380
## 6 5.5 390
calls<-data.frame(Hour=dta$Hour,
Calls=dta$Calls)
ggplot(data=dta,aes(x=Hour,y=Calls,group=1))+
geom_bar(width=1,stat="identity",fill="cyan",
color="skyblue",alpha=0.2)+
geom_abline(intercept=mean(dta$Calls),slope = 0,
size = 1,color="lightpink") +
coord_polar(theta="x",start=-pi/12) +
theme_bw()