r - 如何在r中绘制不同月份的比较
问题描述
我试图展示新求职者在新冠时间几个月内的增长。因此,我从完整的 df 中过滤了我需要的统计数据表,并将其命名为“dist.newseek”
Cdata <- structure(list(Month = c(
"2020-01", "2020-01", "2020-01", "2020-01",
"2020-01", "2020-02", "2020-02", "2020-02", "2020-02", "2020-02",
"2020-03", "2020-03", "2020-03", "2020-03", "2020-03", "2020-04",
"2020-04", "2020-04", "2020-04", "2020-04"
), District = c(
"Dan",
"Jerusalem", "North", "Sharon", "South", "Dan", "Jerusalem",
"North", "Sharon", "South", "Dan", "Jerusalem", "North", "Sharon",
"South", "Dan", "Jerusalem", "North", "Sharon", "South"
), NewSeekers = c(
6551L,
3589L, 6154L, 4131L, 4469L, 5529L, 2721L, 5061L, 3464L, 3612L,
231315L, 137479L, 159445L, 123753L, 104868L, 55038L, 33995L,
40572L, 31373L, 23914L
)), row.names = c(NA, -20L), class = "data.frame")
我正在努力寻找最好的方式来展示 1 月到 4 月之间 NewSeekers 的成长如果你有任何其他情节建议,我会接受
至于问题,我用了ggplot,geom_text
但是圆圈不完整,文字根本不清楚
这是我使用的代码:
dist.newseek <- Cdata %>%
group_by(Month,District) %>%
summarise(NewSeekers=sum(NewSeekers))
ggplot(dist.newseek, aes(x="", y=NewSeekers, group=District, color=District, fill=District)) +
geom_bar(width = 1, stat = "identity") +
geom_text(aes(label = paste0(NewSeekers,
" (",
scales::percent(NewSeekers / sum(NewSeekers)),
")")),
position = position_stack(vjust = 0.5)) +
coord_polar("y", start=0) + facet_wrap(~ Month) +
theme(axis.text = element_blank(),
axis.ticks = element_blank(),
panel.grid = element_blank())
和情节:
解决方案
我猜您希望在每个月内计算百分比。然后你可能想按月份分组并总结。
group_by(dist.newseek, Month) %>%
mutate(percent=NewSeekers / sum(NewSeekers)) %>%
ggplot(aes(x="", y=percent, fill=District)) +
geom_bar(stat = "identity") +
facet_wrap(~ Month, ncol=3) +
coord_polar("y", start=0) +
geom_text(aes(label = paste0(NewSeekers,
"\n (",
scales::percent(percent, accuracy=1),
")")),
position = position_stack(vjust = 0.5), size=1.5) +
theme(axis.text = element_blank(),
axis.ticks = element_blank(),
panel.grid = element_blank(),
text=element_text(size=10),
legend.position = c(0.7, 0.3)) +
labs(x="", y="") +
guides(fill=guide_legend(ncol=2))
推荐阅读
- android - 将 png 转换为可绘制,然后是颜色过滤器,然后是位图 - 不工作
- c - Unix系统编程:获取要传递给getaddrinfo的网络标识符
- javascript - 这两种连接用法有什么区别?
- javascript - 从firebase函数调用json文件
- php - PHP cURL POST 数据集
- javascript - Graphql - 从生成的 JSON 文件创建模式
- sql - 触发器禁止向表的列插入负数
- shell - 变量中的命令不与文件名中的空白一起运行
- c# - 在 xamarin android 中播放受密码保护的 mp3 歌曲
- scala - scala 未来 firstcompletedof 的超时