library(ggplot2)

data(mtcars)

mtcars$cyl <- factor(mtcars$cyl)

mtcars <- mtcars[order(mtcars$mpg), ]

mtcars$name <- rownames(mtcars)

mtcars$name <- factor(mtcars$name, levels = rownames(mtcars))

ggplot(mtcars, aes(x="data", y="labels", color = cyl, label=mpg)) +

geom_segment(aes(y ="labels" ,

x = "data",

yend ="labels" ,

xend ="data"),

color = "gray", size=2) +

geom_point(stat='identity', size=6) +

geom_text(color="white", size=2) +

labs(title="Lollipop Chart")
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.