Bar chart with hchart()
mpg %>%
count(class, year) %>%
hchart( "column", hcaes(x = class, y = n, group = year))
Bubble plot
data(stars)
stars %>% hchart("scatter", hcaes(temp, lum, size = radiussun))
axis type = “logarithmic”
stars %>%
hchart("scatter", hcaes(temp, lum, size = radiussun)) %>%
hc_xAxis(type = "logarithmic") %>% ####
hc_yAxis(type = "logarithmic") ####
Adding colors via colorize
colors <- c("#FB1108","#FD150B","#FA7806","#FBE426","#FCFB8F", #####
"#F3F5E7", "#C7E4EA","#ABD6E6","#9AD2E1") #####
stars$color <- colorize(log(stars$distance), colors) #####
stars %>%
hchart( "scatter", hcaes(temp, lum, size = radiussun, color=color)) %>% #####
hc_xAxis(type = "logarithmic") %>%
hc_yAxis(type = "logarithmic", gridLineWidth = 0)
Axis titles
colors <- c("#FB1108","#FD150B","#FA7806","#FBE426","#FCFB8F",
"#F3F5E7", "#C7E4EA","#ABD6E6","#9AD2E1")
stars$color <- colorize(log(stars$distance), colors)
stars %>%
hchart( "scatter", hcaes(temp, lum, size = radiussun, color=color)) %>%
hc_xAxis(type = "logarithmic" , title = list(text ="Temperature")) %>% ######
hc_yAxis(type = "logarithmic", title = list(text ="Luminosity")) %>% ######
hc_title(text='Sweet bubble plot') ######
Custom hover text
colors <- c("#FB1108","#FD150B","#FA7806","#FBE426","#FCFB8F",
"#F3F5E7", "#C7E4EA","#ABD6E6","#9AD2E1")
stars$color <- colorize(log(stars$distance), colors)
x <- c("Luminosity", "Temperature", "Distance") ##### what do you want to name the values
y <- sprintf("{point.%s:.2f}", c("lum", "temp", "distance")) ##### column names of the values & formatting to cut off at 2 decimal places
tltip <- tooltip_table(x, y) ##### creates the tooltip
stars %>%
hchart( "scatter", hcaes(temp, lum, size = radiussun, color=color)) %>%
hc_xAxis(type = "logarithmic" , title = list(text ="Temperature")) %>%
hc_yAxis(type = "logarithmic", title = list(text ="Luminosity")) %>%
hc_title(text='Sweet bubble plot') %>%
hc_tooltip(useHTML = TRUE, headerFormat = "", pointFormat = tltip) ##### use the tooltip