I am working on a horizontal bar plot for some visualizations using the highcharter library in R. However, I see that the legends are not shown according to the color scheme defined by the group variable.
library(highcharter)
library(tidyverse)
df%>%
group_by(course_code) %>%
hchart("bar", hcaes(x = course_code, y = completion_rate,
color = Language, group = Language)) %>%
hc_add_theme(hc_theme_google()) %>%
hc_tooltip(pointFormat = "<b> Completion rate: </b> {point.completion_rate}") %>%
hc_title(text = "Course Completion Rates",
style = list(fontSize = "15px", fontWeight = "bold")) %>%
hc_xAxis(title = list(text = "Courses")) %>%
hc_yAxis(title = list(text = "Completion Rate"))
Is there a way to fix this?
Data: here
>Solution :
You will need fill aesthetics:
library(highcharter)
library(tidyverse)
df1%>%
group_by(course_code) %>%
hchart("bar", hcaes(x = course_code, y = completion_rate,
fill = Language, group=Language)) %>%
hc_add_theme(hc_theme_google()) %>%
hc_tooltip(pointFormat = "<b> Completion rate: </b> {point.completion_rate}") %>%
hc_title(text = "Course Completion Rates",
style = list(fontSize = "15px", fontWeight = "bold")) %>%
hc_xAxis(title = list(text = "Courses")) %>%
hc_yAxis(title = list(text = "Completion Rate"))

