A lollipop plot is very close from both scatterplot and barplot. Thus, 2 types of input format work to build it. You can have **2 numerical values** like for a scatterplot, or **one numerical and one categorical** variable like for the barplot.

In any case, we will use ggplot2 to realise the figure. There are 2 components for a lollipop plot: the stem which is a segment drawn with geom_segment, and the point that is made using geom_point.

Here are the code for these 2 examples, showing how it works for both data formats. Note that you probably need to custom the appearance of these graphics. A complete section of the gallery is dedicated to lollipop charts.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# Library library(tidyverse) # --- NUMERIC + NUMERIC # Create data data=data.frame(x=seq(1,30), y=abs(rnorm(30))) # Plot ggplot(data, aes(x=x, y=y)) + geom_point() + geom_segment( aes(x=x, xend=x, y=0, yend=y)) # --- NUMERIC + FACTOR # Create data data=data.frame(x=LETTERS[1:26], y=abs(rnorm(26))) # Plot ggplot(data, aes(x=x, y=y)) + geom_point() + geom_segment( aes(x=x, xend=x, y=0, yend=y)) |

Related

Make a search

## Leave a Reply

Be the First to Comment!