这是我的数据格式化的方式。我需要先使其“整洁”还是可以吗?
Council `2019` `2020`
<chr> <dbl> <dbl>
1 1 260 206
2 2 130 157
3 3 42 48
4 4 38 42
5 5 45 126
6 6 34 26
7 7 13 21
8 8 30 13
9 9 16 15
10 10 15 43
我的目标是为每个理事会创建一个并排的条形图,以显示每个理事会在2019年至2020年之间的差异。
谢谢
如果您需要没有分面的并排条形图,请尝试以下操作:
library(tidyverse)
df %>%
pivot_longer(-1, names_to = "year", values_to = "count") %>%
ggplot(aes(Council, count, fill = year)) +
geom_col(position = "dodge2") +
scale_x_continuous(breaks = 1:10)
数据
df <- structure(list(Council = 1:10, `2019` = c(260L, 130L, 42L, 38L,
45L, 34L, 13L, 30L, 16L, 15L), `2020` = c(206L, 157L, 48L, 42L,
126L, 26L, 21L, 13L, 15L, 43L)), row.names = c(NA, -10L), class = c("tbl_df",
"tbl", "data.frame"))
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句