【发布时间】:2020-12-18 06:04:42
【问题描述】:
有没有办法根据它们的 Y 值(又名 count )以动态降序重新排序这些方面 - 无需对顺序进行硬编码(给定与 package 类似的列,具有数百个级别?
library(cranlogs)
library(tidyverse)
tidyverse_downloads <- cran_downloads(
packages = pkgs,
from = "2017-01-01",
to = "2017-06-30") %>%
tibble::as_tibble() %>%
group_by(package)
tidyverse_downloads %>%
ggplot(aes(x = date, y = count)) +
#geom_hline(yintercept = 0, color = "grey40") +
geom_line() +
#geom_smooth(method = "loess") +
theme_minimal() +
facet_wrap(~ package, scale = "free_y",ncol = 2) + theme(axis.text.x = element_text(angle = 90, hjust = 1))
我尝试的是使用包库(tidytext)和scale_y_reordered
tidyverse_downloads %>%
mutate(count = tidytext::reorder_within(count, date, package)) %>%
tidytext::scale_y_reordered() +
ggplot(aes(x = date, y = count)) +
geom_line() +
theme_minimal() +
facet_wrap(~ package, scale = "free_y",ncol = 2) + theme(axis.text.x = element_text(angle = 90, hjust = 1))
但是,这不会产生任何结果。我猜我做错了什么。感谢任何帮助
【问题讨论】: