1
library(ggplot2);library(RColorBrewer)
US <- map_data("state")
USMurder <- USArrests
USMurder$State <- as.factor(tolower(row.names(USArrests)))
ggplot(data = USMurder,aes(map_id =State))+
        geom_map(aes(fill = Murder),map = US,col="white")+
        expand_limits(x = US$long, y = US$lat)+
        scale_fill_gradient(name = "  " , low="white",high = "red")+
        theme_minimal()+
        theme(axis.text=element_blank())+
        labs(list(title = "Murder Rate by US State in 1973 \n (arrests per 100,000 residents)",
                  x = " ", y = " "))

##### 3

library(choroplethr)
library(choroplethrMaps)
library(choroplethrAdmin1)
library(ggplot2)
tw_map <- get_admin1_map("taiwan")
dta <- data.frame(Region=levels(as.factor(tw_map$region)))
dta$Visit <- ifelse(dta$Region %in% c("lienchiang","penghu","pingtung"),0,1)
ggplot(data = dta,aes(map_id =Region))+
        geom_map(aes(fill = as.factor(Visit)),map = tw_map,col="black")+
        expand_limits(x = tw_map$long, y = tw_map$lat)+
        theme_minimal()+
        scale_fill_manual(values=c("white","yellow"),name="Visit",label=c("No","Yes"))+
        theme_bw()+
        theme_minimal()+
        theme(axis.text=element_blank())+
        labs(list(title = "Visit or Not",
                  x = " ", y = " "))

4
world <- map_data("world")
dta <- data.frame(Country = levels(as.factor(world$region)))
dta$Visit <- ifelse(dta$Country %in% c("China","Japan","South Korea","Taiwan",
                                       "USA","Philippines"),1,0)
ggplot(data = dta,aes(map_id =Country))+
        geom_map(aes(fill = as.factor(Visit)),map = world,col="black")+
        expand_limits(x = world$long, y = world$lat)+
        scale_fill_manual(values=c("white","red"),name="Visit",label=c("No","Yes"))+
        theme_bw()+
        theme_minimal()+
        theme(axis.text=element_blank())+
        labs(list(title = "Visited So Far",
                  x = " ", y = " "))

7
library(ggmap)
bf <- c("台南市東區中華東路1段366號", "台南市中西區中山路162號","台南市中西區西門路一段658")
bf2 <- data.frame(geocode(bf),Place =c("Dubu house","Thai Town","Silver Spoon"))
tan <- get_map(location = c(lon = 120.21, lat = 22.99), zoom = 13, maptype = "roadmap")
ggmap(tan)+
        labs( x = "Longitude", y = "Latitude")+
        geom_point(data = bf2 , aes(x = lon, y = lat), size = 5,color = "pink") +
        geom_point(data = bf2 , aes(x = lon, y = lat), size = 3,color = "violet")+
        geom_text(data = bf2 , aes(x = lon, y = lat, label = Place),
                  size = 5, color = "red", vjust = 0, hjust = 0)

Date

1
table(weekdays(seq(as.Date("1994-01-21"), by = "1 years", length = 100)))

   Friday    Monday  Saturday    Sunday  Thursday   Tuesday Wednesday 
       15        14        14        15        13        14        15 
3
regis <- as.Date("2012-09-17")
today <- Sys.Date()
as.POSIXct(today) - as.POSIXct(regis)
Time difference of 1330 days