棒棒糖图表数据可视化ggplot2
Lollipop chart data visualization ggplot2
我对 Rstudio 完全陌生。
我想使用一个水平棒棒糖图在国家一级可视化与我的变量“UNEMP”相关的数据,但我不太确定如何准备我的数据(因为找不到我的变量),也不确定要使用哪个代码来绘制他们。
这是我的数据:
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")
这是 RStudio 认为我的变量“缺失”的证据。
exists("UNEMP")
[1] FALSE
怎么办?提前谢谢你。
这是一个基本示例,说明如何使用 ggplot2
实现您想要的结果。基本上,您可以通过组合 geom_segment
和 geom_point
来创建棒棒糖图表。我还利用 reorder
按失业率 (?) 对国家进行排序:
library(ggplot2)
ggplot(data, aes(UNEMP, reorder(COUNTRY, UNEMP))) +
geom_segment(aes(xend = 0, yend = COUNTRY)) +
geom_point() +
labs(y = NULL, x = "Unemployment rate")
我对 Rstudio 完全陌生。 我想使用一个水平棒棒糖图在国家一级可视化与我的变量“UNEMP”相关的数据,但我不太确定如何准备我的数据(因为找不到我的变量),也不确定要使用哪个代码来绘制他们。
这是我的数据:
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")
这是 RStudio 认为我的变量“缺失”的证据。
exists("UNEMP")
[1] FALSE
怎么办?提前谢谢你。
这是一个基本示例,说明如何使用 ggplot2
实现您想要的结果。基本上,您可以通过组合 geom_segment
和 geom_point
来创建棒棒糖图表。我还利用 reorder
按失业率 (?) 对国家进行排序:
library(ggplot2)
ggplot(data, aes(UNEMP, reorder(COUNTRY, UNEMP))) +
geom_segment(aes(xend = 0, yend = COUNTRY)) +
geom_point() +
labs(y = NULL, x = "Unemployment rate")