我想根據變數畫一個桑基圖time。基本上,我想time在 y 軸上,temperatures并在 x 軸上humidity分組date。如您所見,時間顯示不正確。為什么?另外,如何更改humidity列的大小以適合框?
示例代碼:
library(ggplot2)
library(ggalluvial)
df$temperature<-round(df$temperature, digits = 0)
df$humidity<-round(df$humidity, digits = 2)
ggplot(df, aes(axis1 = temperature, axis2 = humidity, y = time))
geom_alluvium(aes(fill = date))
scale_x_discrete(limits = c("temperature", "humidity"))
geom_stratum()
geom_text(stat = "stratum", aes(label = after_stat(stratum)))
theme_bw()
樣本資料:
df<-structure(list(time = structure(c(63285, 63885, 64485, 65085,
65685, 66285, 66885, 67485, 68085, 68685, 69285, 69885, 70485,
71085, 71685, 72285, 72885, 73485, 74085, 74685, 75285, 75885,
76485, 77085, 77685, 78285, 78885, 79485, 80085, 80685, 81285,
81885, 82485, 83085, 83685, 84285, 84885, 85485, 86085, 285,
885, 1485, 2085, 2685, 3285, 3885, 4485, 5085, 5685, 6285), class = c("hms",
"difftime"), units = "secs"), temperature = c(6.31, 14.81, 17.13,
16.56, 16.44, 16.44, 16.56, 16.69, 16.88, 17, 17.13, 17.19, 17.31,
17.5, 17.81, 18.06, 18.19, 18.25, 18.25, 18.19, 18.06, 17.94,
17.81, 17.75, 17.63, 17.5, 17.44, 17.38, 17.25, 17.19, 17.13,
17.06, 17, 17, 16.88, 16.88, 16.88, 16.81, 16.81, 16.81, 16.81,
16.88, 16.88, 16.88, 16.88, 16.88, 16.81, 16.81, 16.81, 16.75
), humidity = c(0.674, 0.643, 0.472, 0.503, 0.515, 0.523, 0.53,
0.539, 0.541, 0.546, 0.548, 0.549, 0.555, 0.561, 0.578, 0.577,
0.575, 0.579, 0.596, 0.597, 0.599, 0.604, 0.612, 0.616, 0.619,
0.623, 0.637, 0.638, 0.639, 0.639, 0.643, 0.646, 0.649, 0.653,
0.654, 0.66, 0.664, 0.668, 0.672, 0.676, 0.691, 0.693, 0.693,
0.694, 0.693, 0.694, 0.698, 0.691, 0.694, 0.697), date = c("04/01/2022",
"04/01/2022", "04/01/2022", "04/01/2022", "04/01/2022", "04/01/2022",
"04/01/2022", "04/01/2022", "04/01/2022", "04/01/2022", "04/01/2022",
"04/01/2022", "04/01/2022", "04/01/2022", "04/01/2022", "04/01/2022",
"04/01/2022", "04/01/2022", "04/01/2022", "04/01/2022", "04/01/2022",
"04/01/2022", "04/01/2022", "04/01/2022", "04/01/2022", "04/01/2022",
"04/01/2022", "04/01/2022", "04/01/2022", "04/01/2022", "04/01/2022",
"04/01/2022", "04/01/2022", "04/01/2022", "04/01/2022", "04/01/2022",
"04/01/2022", "04/01/2022", "04/01/2022", "05/01/2022", "05/01/2022",
"05/01/2022", "05/01/2022", "05/01/2022", "05/01/2022", "05/01/2022",
"05/01/2022", "05/01/2022", "05/01/2022", "05/01/2022")), row.names = c(NA,
-50L), class = "data.frame")

uj5u.com熱心網友回復:
根據我對提到的 y 軸的了解,您正試圖實作這樣的目標(這就是我所取得的成就)......也許可以查看其他
您可以在堆疊中添加松散的文本以識別它們,或者也可以對 x 軸進行自定義標簽。
附帶說明:將顏色引數移入 geom_alluvium() 的 aes 呼叫不能按預期 100% 作業
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/407000.html
標籤:
