我正在寻找一个在ggplot中的包来制作下面的图。

我知道ggridges,但它没有3个维度。
发布于 2021-04-25 00:58:56
您还可以使用ggridges欺骗x轴和网格线以获得相同的效果:
library(ggridges)
library(ggplot2)
slant_factor = 5 # How many units x shift per category? Won't work with zero
intercepts = (20 * (0:4)) / slant_factor + 0.8
ggplot(lincoln_weather,
aes(x = `Mean Temperature [F]` - as.numeric(Month)*slant_factor,
y = Month, fill = stat(x))) +
geom_abline(slope = -1 / slant_factor ,
intercept = intercepts,
color = "gray90") +
geom_density_ridges_gradient(scale = 3, rel_min_height = 0.01, gradient_lwd = 1.) +
scale_x_continuous(expand = c(0, 0),
breaks = 20 * (0:4)) +
scale_y_discrete(expand = expand_scale(mult = c(0.01, 0.25))) +
scale_fill_viridis_c(name = "Temp. [F]", option = "C") +
labs(
title = 'Temperatures in Lincoln NE',
subtitle = 'Mean temperatures (Fahrenheit) by month for 2016'
) +
theme_ridges(font_size = 13, grid = TRUE) +
theme(axis.title.y = element_blank(), panel.grid.major.x = element_blank())

发布于 2021-04-24 23:13:09
解决您的问题的两个可能的选项(如果我理解正确的话)如下:
# dummy data
df <- data.frame(grps = factor(sort(rep(c("a","b","c"), 10))),
seq = rep(1:10, 3),
vlr = c(c(1:6, 4:1), c(1:6, 4:1) + 1, c(1:6, 4:1) + 2))使用plotly:
library(plotly)
fig <- plot_ly(df, x = ~vlr, y = ~seq, z = ~grps, type = 'scatter3d', mode = 'lines',
transforms = list(
list(
type = 'groupby',
groups = df$grps)))
fig # you have to rotate it

使用rayshader将线状图转换为3D,但它将转换为条形图(它的工作诀窍是:定义高度的值进入颜色美感)
library(ggplot2)
library(rayshader)
gl <- ggplot2::ggplot(df, aes(x = grps, y = seq, group = grps, color = vlr)) +
ggplot2::geom_line()
rayshader::plot_gg(gl)

在使用geom_ridgeline()并通知height参数时,ggridges可以处理第三维,但它似乎有点有限(尽管我没有阅读文档以及如何润色和改进这种类型的图表:
library(ggplot2)
library(ggridges)
ggplot2::ggplot(df, aes(x = seq, height = vlr, y = grps, color = grps)) +
ggridges::geom_ridgeline()

https://stackoverflow.com/questions/67243131
复制相似问题