Search code examples
rggplot2r-highcharter

how to plot a Vertical Likert Line Chart with Categories by ggplot2 or highcharter?


I want to create a Vertical Likert Line Chart , is there anyway to plot it by ggplot2 or highcharter ?

here is the example chart:

enter image description here

data example :

value1 <- abs(rnorm(26))*2
data <- data.frame(
  x=LETTERS[1:26], 
  value1=value1, 
  value2=value1+1+rnorm(26, sd=1) 
)

Solution

  • library(tidyverse)
    data %>%
      pivot_longer(-x) %>%
      ggplot(aes(x, value, color = name, group = name)) +
      geom_line() +
      geom_point() +
      coord_flip()
    

    P.S. --- Since ggplot2 3.3.0 from March 2020, you can skip the "coord_flip" step and describe the axes directly in the orientation you want them, but the geom_line step still needs a nudge to display correctly:

    ...
    ggplot(aes(value, x, color = name, group = name)) +
      geom_line(orientation = "y") +
      geom_point()
    

    enter image description here