Untuk membuat Dumbbell Plot di R menggunakan ggplot2, kita menggunakan fungsi geom_dumbbell().

ylabel <- c("first","second","third")
x1 <- c(1,2,3)
x2 <- c(4,3,5)
datamain <- data.frame(ylabel,x1,x2)

library(ggplot2)
library(ggalt)
## Registered S3 methods overwritten by 'ggalt':
##   method                  from   
##   grid.draw.absoluteGrob  ggplot2
##   grobHeight.absoluteGrob ggplot2
##   grobWidth.absoluteGrob  ggplot2
##   grobX.absoluteGrob      ggplot2
##   grobY.absoluteGrob      ggplot2
library(tidyverse)
## ── Attaching packages
## ───────────────────────────────────────
## tidyverse 1.3.2 ──
## ✔ tibble  3.1.8      ✔ dplyr   1.0.10
## ✔ tidyr   1.2.1      ✔ stringr 1.5.0 
## ✔ readr   2.1.3      ✔ forcats 0.5.2 
## ✔ purrr   0.3.5      
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
ggplot() + geom_dumbbell(data = datamain,
                        aes(y = ylabel,
                            x = x1,
                            xend = x2),
                        size = 1.5)
## Warning: Using the `size` aesthietic with geom_segment was deprecated in ggplot2 3.4.0.
## ℹ Please use the `linewidth` aesthetic instead.

ylabel <- c("first","second","third")
x1 <- c(1,2,3)
x2 <- c(4,3,5)
datamain <- data.frame(ylabel,x1,x2)

library(ggplot2)
library(ggalt)
library(tidyverse)

ggplot() + geom_dumbbell(data = datamain,
                        aes(y = ylabel,
                            x = x1,
                            xend = x2),
                        size = 1.5,
                        size_x = 5,
                        size_xend = 9)

ylabel <- c("first","second","third",
            "fourth","fifth","Sixth")
x1 <- c(1,2,4,5,3,2)
x2 <- c(4,3,6,7,5,4)

datamain <- data.frame(ylabel,x1,x2)

library(ggplot2)
library(ggalt)  
library(tidyverse)

ggplot() +
geom_dumbbell(data = datamain, aes(y = ylabel,
                                    x = x1,
                                    xend = x2),
            size = 1.5, color = "purple", size_x = 7,
            size_xend = 7, colour_x = "green",
            colour_xend = "red")