为什么情节的顶部被切断,我该如何解决?我增加了利润,但没有任何区别。
参见 1854 年的曲线,位于左侧驼峰的最顶部。看起来驼峰顶部的线条更细。对我来说,将大小更改为 0.8 并没有帮助。
这是生成此示例所需的代码:
library(tidyverse)
library(ggridges)
t2 <- structure(list(Date = c("1853-01", "1853-02", "1853-03", "1853-04",
"1853-05", "1853-06", "1853-07", "1853-08", "1853-09", "1853-10",
"1853-11", "1853-12", "1854-01", "1854-02", "1854-03", "1854-04",
"1854-05", "1854-06", "1854-07", "1854-08", "1854-09", "1854-10",
"1854-11", "1854-12"), t = c(-5.6, -5.3, -1.5, 4.9, 9.8, 17.9,
18.5, 19.9, 14.8, 6.2, 3.1, -4.3, -5.9, -7, -1.3, 4.1, 10, 16.8,
22, 20, 16.1, 10.1, 1.8, -5.6), year = c("1853", "1853", "1853",
"1853", "1853", "1853", "1853", "1853", "1853", "1853", "1853",
"1853", "1854", "1854", "1854", "1854", "1854", "1854", "1854",
"1854", "1854", "1854", "1854", "1854")), row.names = c(NA, -24L
), class = c("tbl_df", "tbl", "data.frame"), .Names = c("Date",
"t", "year"))
# Density plot -----------------------------------------------
jj <- ggplot(t2, aes(x = t, y = year)) +
stat_density_ridges(
geom = "density_ridges_gradient",
quantile_lines = TRUE,
size = 1,
quantiles = 2) +
theme_ridges() +
theme(
plot.margin = margin(t = 1, r = 1, b = 0.5, l = 0.5, "cm")
)
# Build ggplot and extract data
d <- ggplot_build(jj)$data[[1]]
# Add geom_ribbon for shaded area
jj +
geom_ribbon(
data = transform(subset(d, x >= 20), year = group),
aes(x, ymin = ymin, ymax = ymax, group = group),
fill = "red",
alpha = 0.5)