【发布时间】:2018-09-27 17:58:23
【问题描述】:
我有一个包含长度(整数)和年份(因子)的数据集,我想使用 ggridges 绘制它。这是一个包含整数和因子数据的类似数据集。如何更改 y 轴上 Species 的顺序(即因子)?
library(ggplot2)
library(ggridges)
library(viridis)
library(datasets)
order <- c("setosa", "versicolor", "virginica")
ggplot(iris, aes(x = Sepal.Length, y = Species, fill = ..x..), order(Species)) +
geom_density_ridges_gradient(scale = 3, rel_min_height = 0.01) +
scale_fill_viridis(name = "Sepal.Length", option = "A") +
theme_ridges() +
labs(title = 'Sepal Length distributions for irises')
这里,order(Species) 或 order(order) 不起作用。
我试过了:
scale_y_reverse(breaks=order), expand = c(0.01, 0))
但后来意识到这是针对连续变量(尝试将年份作为数字 - 不起作用)。
【问题讨论】:
标签: r ggplot2 ridgeline-plot ggridges