Home > Software design >  Lollipop chart data visualization ggplot2
Lollipop chart data visualization ggplot2

Time:04-04

I am completely new with Rstudio. I would like to visualize data related to my variable "UNEMP" at country level using one horizontal lollipop plot, but I am not really sure what to do to prepare my data (since my variable is not found) nor which code to use to plot them.

Here's my data:

dput(data)

structure(list(COUNTRY = c("Austria", "Belgium", "Bulgaria", "Croatia", "Cyprus", "Czech Republic", "Denmark", "Estonia", "Finland", "France", "Germany", "Greece", "Hungary", "Ireland", "Italy", "Latvia", "Lithuania", "Luxembourg", "Malta", "Netherlands", "Poland", "Portugal", "Romania", "Slovakia", "Slovenia", "Spain", "Sweden"), PERFAKE = c(31, 31, 40, 47, 45, 40, 25, 23, 18, 39, 24, 55, 52, 38, 37, 35, 23, 38, 27, 25, 48, 32, 41, 45, 31, 53, 25), FORDISINFO = c("2764", "3803", "1929", "3148", "2783", "2296", "3449", "1678", "3443", "3072", "1908", "3246", "1482", "2766", "3031", "0.382", "3.26", "2637", "3.4", "2867", "3317", "3484", "2768", "2744", "3457", "3322", "2896"), PARDISINFO = c("2322", "2778", "1523", "2.87", "3009", "2876", "3651", "2866", "2.84", "3235", "2926", "2244", "1113", "3621", "1951", "2893", "3465", "2916", "1208", "2859", "2656", "3533", "2485", "2519", "1382", "2971", "3345"), MEDIALIT = c(59, 66, 32, 43, 43, 51, 72, 70, 78, 59, 64, 40, 41, 69, 51, 54, 52, 62, 44, 71, 53, 62, 36, 44, 59, 57, 71), POLAR = c("1838", "1627", "0.68", "0.995", "2062", "1885", "3037", "1343", "3155", "0.613", "1521", "0.45", "0.023", "1664", "0.651", "1817", "2582", "3.25", "0.528", "1477", "0.048", "1695", "1344", "1004", "0.388", "0.12", "2136"), CULBACK = c(37, 36, 52, 39, 50, 49, 24, 37, 22, 38, 35, 63, 63, 25, 51, 41, 28, 17, 63, 34, 37, 26, 33, 54, 38, 26, 19), UNEMP = c(4.8, 5.9, 5.2, 8.4, 8.4, 2.2, 5.1, 5.4, 7.4, 9, 3.4, 19.3, 3.7, 5.7, 10.6, 7.4, 6.2, 5.6, 3.7, 3.8, 3.8, 7, 4.2, 6.5, 5.1, 15.3, 6.4), PERCOR = c(77, 75, 43, 47, 58, 44, 87, 74, 86, 69, 80, 48, 44, 74, 53, 56, 60, 80, 54, 82, 58, 62, 44, 50, 60, 62, 85), NOREPRES = c(40, 44, 44, 34, 64, 67, 14, 76, 33, 44, 24, 83, 50, 0, 72, 66, 53, 35, 40, 20, 36, 60, 58, 49, 50, 58, 12)), row.names = c(NA, -27L), class = "data.frame")

And here's the proof my variable is considered "missing" by RStudio.

exists("UNEMP")
[1] FALSE

What to do? Thank you in advance.

CodePudding user response:

Here is a basic example of how could achieve your desired result using ggplot2. Basically you could create a lollipop chart by combing a geom_segment with a geom_point. Also I make use of reorder to order the countries by unemployment rate (?):

library(ggplot2)

ggplot(data, aes(UNEMP, reorder(COUNTRY, UNEMP)))  
  geom_segment(aes(xend = 0, yend = COUNTRY))  
  geom_point()  
  labs(y = NULL, x = "Unemployment rate")

  • Related