Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Incorrect legend color shown on Highchart horizontal bar plot

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.

enter image description here

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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"))

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading