Dot Plot (Dumbbell Plot)

library(tidyverse)    # untuk manupulasi, merapikan, & visualisasi data
set.seed(2000)
df1 = tibble(var = 'A', val = rnorm(n = 25, mean = 5.5, sd = 1.5))
df2 = tibble(var = 'B', val = rnorm(n = 15, mean = 4.5, sd = 1.0))
df3 = tibble(var = 'C', val = rnorm(n = 20, mean = 5.0, sd = 1.0))
df4 = tibble(var = 'D', val = rnorm(n = 10, mean = 4.0, sd = 0.5))
df5 = tibble(var = 'E', val = rnorm(n = 13, mean = 5.0, sd = 1.5))

df <- rbind(df1, df2, df3, df4, df5) %>%
  mutate(Variable = as_factor(var),
         value = round(val, 2)) %>%
  select(Variable, value)
dumbbell_plot <- df %>%
  group_by(Variable) %>%
  summarise(min = min(value), max = max(value)) %>%
  ggplot(aes(x = min,
             xend = max,
             y = Variable), ) +
  ggalt::geom_dumbbell(size =3,
                       size_x = 12,
                       size_xend = 12,
                       color = '#edce79',
                       colour_x = '#edce79',
                       colour_xend = '#edce79') +
  ggalt::geom_dumbbell(size = 3,
                       size_x = 9,
                       size_xend = 9,
                       color = '#edce79',
                       colour_x = '#660d20',
                       colour_xend = '#094568') +
  geom_text(aes(x = min,
                y = Variable,
                label = round(min, 1)), 
            size = 3,
            fontface = 'bold',
            color = 'white') +
  geom_text(aes(x = max,
                y = Variable,
                label = round(max, 1)), 
            size = 3,
            fontface = 'bold',
            color = 'white') +
  scale_x_continuous(limits = c(0, 10),
                     breaks = seq(0, 10, by = 2)) +
  theme_minimal() +
  theme(
    axis.title = element_blank(),
    axis.text = element_blank(),
    axis.line = element_blank(),
    panel.grid.major = element_blank(),
    panel.grid.minor = element_blank(),
    panel.background = element_rect(fill = '#FFFFFF',
                                    color = NA),
    plot.background = element_rect(fill = '#FFFFFF',
                                   color = '#FFFFFF')
  )
## Registered S3 methods overwritten by 'ggalt':
##   method                  from   
##   grid.draw.absoluteGrob  ggplot2
##   grobHeight.absoluteGrob ggplot2
##   grobWidth.absoluteGrob  ggplot2
##   grobX.absoluteGrob      ggplot2
##   grobY.absoluteGrob      ggplot2