I want to create a Vertical line chart , is there anyway to plot it by ggplot2 or highcharter ?
here is the example chart:
![](https://forum.posit.co/uploads/default/original/3X/f/5/f5f1c36fad335af02c663ad9a80185ce04448a14.png)
data example :
value1 <- abs(rnorm(26))*2
data <- data.frame(
x=LETTERS[1:26],
value1=value1,
value2=value1+1+rnorm(26, sd=1)
)
There are several ways to achieve this result. I would definitely suggest the tidy one
library(tidyverse)
value1 <- abs(rnorm(26))*2
data <- data.frame(
x=LETTERS[1:26],
value1=value1,
value2=value1+1+rnorm(26, sd=1)
)
# Option 1: dirty
ggplot(data,
aes(x = x))+
geom_point(aes(y = value1), color = "red")+
geom_line(aes(y = value1, group = 1), color = "red")+
geom_point(aes(y = value2), color = "blue")+
geom_line(aes(y = value2, group = 2), color = "blue")+
coord_flip()
![image](https://forum.posit.co/uploads/default/original/3X/c/0/c0fedef0ab9ffe54e52e04009bbbaccbc7cd8b64.png)
# Option 2: tidy
data %>%
pivot_longer(cols = c("value1", "value2"),
names_to = "v_group") %>%
ggplot(aes(x = x, y = value, color = v_group, group = v_group)) +
geom_point()+
geom_line()+
coord_flip()
![image](https://forum.posit.co/uploads/default/original/3X/7/b/7b4e897d017bf352d6157d50183069c71690972e.png)
Created on 2021-04-13 by the reprex package (v1.0.0)
system
Closed
3
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
If you have a query related to it or one of the replies, start a new topic and refer back with a link.