Below are the solutions to these exercises on “Data Visualization With Highcharter.”
#################### # # # Exercise 1 # # # #################### library("highcharter") data(mpg, package = "ggplot2") hchart(mpg, "scatter", hcaes(x = displ, y = hwy)) #################### # # # Exercise 2 # # # #################### library("highcharter") data(mpg, package = "ggplot2") hchart(mpg, "scatter", hcaes(x = displ, y = hwy, group = class)) #################### # # # Exercise 3 # # # #################### highchart() %>% hc_chart(type = "column") %>% hc_add_series(data = c(5000, 6000, 7000, 8000, 9900), name = "Downloads") #################### # # # Exercise 4 # # # #################### highchart() %>% hc_chart(type = "column") %>% hc_title(text = "A highcharter chart") %>% hc_add_series(data = c(5000, 6000, 7000, 8000, 9900) ) #################### # # # Exercise 5 # # # #################### highchart() %>% hc_chart(type = "column") %>% hc_title(text = "A highcharter chart") %>% hc_xAxis(categories = 2012:2016) %>% hc_add_series(data = c(5000, 6000, 7000, 8000, 9900), name = "Sales") #################### # # # Exercise 6 # # # #################### data(diamonds, package = "ggplot2") hchart(diamonds$cut, colorByPoint = TRUE, name = "Cut") #################### # # # Exercise 7 # # # #################### hchart(diamonds$price, color = "#B71C1C", name = "Price") #################### # # # Exercise 8 # # # #################### install.packages("forecast") library("forecast") airforecast <- forecast(auto.arima(AirPassengers), level = 95) hchart(airforecast) #################### # # # Exercise 9 # # # #################### data(unemployment) hcmap("countries/us/us-all-all", data = unemployment, name = "Unemployment", value = "value", joinBy = c("hc-key", "code"), borderColor = "transparent")%>% hc_colorAxis(dataClasses = color_classes(c(seq(0, 10, by = 2), 50))) #################### # # # Exercise 10 # # # #################### data(unemployment) hcmap("countries/us/us-all-all", data = unemployment, name = "Unemployment", value = "value", joinBy = c("hc-key", "code"), borderColor = "transparent") %>% hc_colorAxis(dataClasses = color_classes(c(seq(0, 10, by = 2), 50))) %>% hc_legend(layout = "vertical", align = "right", floating = TRUE, valueDecimals = 0, valueSuffix = "%")
Leave a Reply