相关疑难解决方法(0)

gganimate如何订购有序的酒吧时间序列?

我有一个时间序列的数据,我在y轴上绘制疾病的诊断率DIAG_RATE_65_PLUS,并在x轴上绘制地理组NAME作为简单的条形图.我的时间变量是ACH_DATEyearmon动画在标题中看到的循环.

df %>% ggplot(aes(reorder(NAME, DIAG_RATE_65_PLUS), DIAG_RATE_65_PLUS)) +
  geom_bar(stat = "identity", alpha = 0.66) +
  labs(title='{closest_state}') +
  theme(plot.title = element_text(hjust = 1, size = 22),
        axis.text.x=element_blank()) +
  transition_states(ACH_DATEyearmon, transition_length = 1, state_length = 1) +
  ease_aes('linear')
Run Code Online (Sandbox Code Playgroud)

我已经重新排序,NAME所以它排名靠前DIAG_RATE_65_PLUS.

gganimate产生的是什么:

有趣的情节

我现在有两个问题:

1)gganimate如何重新排序数据?有一些整体的一般重新排序,但每个月没有框架,DIAG_RATE_65_PLUS从最小到最大的组完美排序.理想情况下,我希望最后一个月"2018年8月"完美订购.所有前几个月的x轴都可以根据NAME"2018年8月" 的订购而定.

2)在gganimate中是否有一个选项,其中组在条形图中每个月"转移"到正确的等级?

我的评论查询图:

https://i.stack.imgur.com/s2UPw.gif https://i.stack.imgur.com/Z1wfd.gif

@JonSpring

    df %>%
  ggplot(aes(ordering, group = NAME)) +
  geom_tile(aes(y = DIAG_RATE_65_PLUS/2, 
                height = DIAG_RATE_65_PLUS,
                width = 0.9), alpha = 0.9, fill = …
Run Code Online (Sandbox Code Playgroud)

animation r ggplot2 dplyr gganimate

8
推荐指数
2
解决办法
2015
查看次数

使用gganimate和view_follow和geom_tile时如何摆脱由coord_flip引起的轴闪烁?

假设我们有这个带有缩放比例的条形图竞赛x-axis。从这个考虑的代码完全回答@乔恩春季和添加(有生线之前)非常最后一行:

library(tidyverse)
library(gganimate)
library(gapminder)
theme_set(theme_classic())

gap <- gapminder %>%
    filter(continent == "Asia") %>%
    group_by(year) %>%
    # The * 1 makes it possible to have non-integer ranks while sliding
    mutate(rank = min_rank(-gdpPercap) * 1) %>%
    ungroup()

p <- ggplot(gap, aes(rank, group = country, 
                     fill = as.factor(country), color = as.factor(country))) +
    geom_tile(aes(y = gdpPercap/2,
                  height = gdpPercap,
                  width = 0.9), alpha = 0.8, color = NA) +

    # text in x-axis (requires clip = "off" in …
Run Code Online (Sandbox Code Playgroud)

r flicker ggplot2 gganimate

6
推荐指数
1
解决办法
246
查看次数

带逗号但没有小数的 R 标签

我的目标是用逗号生成标签,但没有小数。假设我有一个包含以下部分的 ggplot:

geom_text(aes(y = var,
              label = scales::comma(round(var))), hjust = 0, nudge_y = 300 )
Run Code Online (Sandbox Code Playgroud)

这几乎是我需要的。它给了我逗号,但有一个小数。我在这里看到(带逗号但没有小数的轴标签 ggplotcomma_format()可能很好,但我认为在我的情况下标签需要一个数据参数,它comma_format()不需要。我能做什么?

更新:

作为发生此问题时的示例,请参阅以下内容,其中使用gganimate了更多内容。代码源自 Jon Spring 在Animated sorted bar chart 中的回答,条形图相互超越

library(gapminder)
library(gganimate)
library(tidyverse)

gap_smoother <- gapminder %>%
    filter(continent == "Asia") %>%
    group_by(country) %>%
    complete(year = full_seq(year, 1)) %>%
    mutate(gdpPercap = spline(x = year, y = gdpPercap, xout = year)$y) %>%
    group_by(year) %>%
    mutate(rank = min_rank(-gdpPercap) * 1) %>%
    ungroup() %>%
    group_by(country) %>%
    complete(year …
Run Code Online (Sandbox Code Playgroud)

format r ggplot2

0
推荐指数
1
解决办法
933
查看次数

标签 统计

ggplot2 ×3

r ×3

gganimate ×2

animation ×1

dplyr ×1

flicker ×1

format ×1