ggmap

library(ggmap)
map <- get_map(location = 'Taiwan', source= 'google', zoom = 7)
ggmap(map)


map <-get_map(location =c(lon=120.12, lat=23.00),zoom =10, language ="zh-TW")
ggmap(map)


library(readr)
Dengue <- read_csv("Dengue_Daily.csv")
head(Dengue)

dataset <- Dengue[(Dengue$發病日 >= '2013-01-01') & (Dengue$發病日 < '2014-01-01'), ]

str(dataset)


dataset <- dataset[(! is.na(dataset$最小統計區中心點X)) & (! is.na(dataset$最小統計區中心點Y)) , ]

dataset <- dataset[(dataset$最小統計區中心點X != 'None') & (dataset$最小統計區中心點Y != 'None'), ]

dataset$最小統計區中心點X <- as.double(dataset$最小統計區中心點X)

dataset$最小統計區中心點Y <- as.double(dataset$最小統計區中心點Y)


map <-get_map(location =c(lon=120.246100, lat=23.121198),zoom =7, language ="zh-TW")

ggmap(map, darken =c(0.5, "white")) + 
  geom_point(aes(x =最小統計區中心點X, y =最小統計區中心點Y),color ="red", data=dataset)
 
ggmap(map, darken =c(0.5, "white")) + 
  facet_grid(.~是否境外移入) +
  geom_point(aes(x =最小統計區中心點X, y =最小統計區中心點Y),color ="red", data=dataset)
 

plotly

library(plotly)

ds <- data.frame(labels=c("A", "B", "C"),
                 values =c(10, 20, 30))

ds

plot_ly(labels=ds$labels, values =ds$values, type ="pie")

plot_ly(labels=ds$labels, values =ds$values, type ="pie", hole=0.6) %>% layout(title="Donut Chart Example")


library(plotly)

month  <-c(1,2,3,4,5)
taipei <-c(92.5,132.6,168.8,159.1,218.7)
tainan <-c(21.2, 30.6, 37.3, 84.6, 184.3)

plot_ly(x =month, y =taipei, fill ="tozeroy", name="taipei",type='scatter', mode='markers') %>% 
  add_trace(x =month, y =tainan, fill ="tozeroy",name="tainan") %>% layout(yaxis=list(title='rainfall'),xaxis=list(title='month'),title="Rainfall For Each Month")



plot_ly(x =month, y =taipei, name="taipei",type='scatter', mode='lines') %>% add_trace(x =month, y =tainan ,name="tainan")

total <-taipei+tainan
y <-list(title="Rainfall")

plot_ly(x =month, y =taipei, fill ="tozeroy", name="taipei",type='scatter', mode='markers') %>% add_trace(x =month, y =total, fill ="tonexty", name="tainan")%>% layout(yaxis=y)


data("diamonds")
diamonds
d <-diamonds[sample(nrow(diamonds), 1000), ]

plot_ly(x =d$carat, y=d$price, color =d$clarity, type='scatter', mode='markers', size =d$carat, text=paste("Clarity", d$clarity))

plot(price ~ carat, data = d, col=clarity)



library(plotly)
library(gapminder)
gapminder


p <- gapminder %>%
  plot_ly(
    x = ~gdpPercap, 
    y = ~lifeExp, 
    size = ~pop, 
    color = ~continent, 
    frame = ~year, 
    text = ~country, 
    hoverinfo = "text",
    type = 'scatter',
    mode = 'markers'
  ) %>%
  layout(
    xaxis = list(
      type = "log"
    )
  )

p

load("C:/Users/nc20/Downloads/cdc.Rdata")

library(ggplot2)
w <-ggplot(data=cdc, aes(x=weight, y =wtdesire))+geom_point(aes(color=factor(gender)))+geom_smooth(method ='lm')

library(plotly)
p <- ggplotly(w)
p
data("economics")

head(economics)
p1 <- plot_ly(economics, x =economics$date, y =economics$unemploy, type='scatter', mode='lines')

p2 <- plot_ly(economics, x =economics$date, y =economics$uempmed, type='scatter', mode='lines')

p <-subplot(p1,p2,margin=0.05)
p

p <-subplot(p1,p2,margin=0.05, nrows = 2)
p


g1 <- ggplot(data = economics, aes(x = date, y = unemploy)) + geom_line(color = 'orange')

g2 <- ggplot(data = economics, aes(x = date, y = uempmed)) + geom_line(color = 'blue')

source('https://raw.githubusercontent.com/ywchiu/cdc_course/master/script/multiplot.R')

multiplot(g1, g2)


library(plotly)
p1 <- ggplotly(g1)

p2 <- ggplotly(g2)

subplot(p1, p2)
subplot(p1, p2, nrows = 2)