library(ggvis)
library(DBI)
library(dplyr)
library(lubridate)
conn <- dbConnect(RMySQL::MySQL(), "richardtwatson.com", dbname="ClassicModels", user="db1", password="student")
o <- dbGetQuery(conn,"SELECT * FROM Orders")
od <- dbGetQuery(conn,"SELECT * FROM OrderDetails")
d <- inner_join(o,od)
d$month <- month(d$orderDate)
# Get the monthly value of orders
d2 <- d %>% group_by(month) %>% summarize(orderValue = sum(quantityOrdered*priceEach))
# Plot data orders by month
# Show the points and the line
d2 %>% ggvis(~month, ~orderValue/1000000) %>%
layer_lines(stroke:='blue') %>%
layer_points(fill:='red') %>%
add_axis('x', title = 'Month') %>%
add_axis('y',title='Order value (millions)', title_offset=30)