我想要 x 軸上的 4 個直方圖;每個站點一個,每組個人都有一個垃圾箱。這些團體是; “mol”、“an”、“地殼”和“其他”。y 軸將是平均豐度。資料幀可以稱為DF。
| 摩爾 | 一個 | 脆皮 | 其他 | 地點 | |
|---|---|---|---|---|---|
| 1 | 1.00000 | 0.0000000 | 12.000000 | 2 | 1 |
| 2 | 0.00000 | 0.6666667 | 28.000000 | 0 | 2 |
| 3 | 0.00000 | 0.3333333 | 2.000000 | 0 | 3 |
| 4 | 4.00000 | 1.3333333 | 3.000000 | 0 | 4 |
| 5 | 12.66667 | 3.3333333 | 1.666667 | 0 | 5 |
ggplot(DF, aes(fill=?, y=?, x=Site)) geom_bar(position="dodge", stat="identity")
我迷失在想放入 fill= 和 y= 部分,我一直在用向量做它,它有效但想把所有的都分組。DF$Site 不同于我一直用于我的簡單直方圖的另一個“站點”: Site <- c(rep("1" , 1) , rep("2" , 1) , rep("3", 1) ,代表(“4”,1),代表(“5”,1))
我會“填充”: fill = rep("whatever",5)
對于我的意思,我會創建一個向量并插入 y= 像這樣: mol = c(1,0,0,4,12.66666667) 我還將使用帶有標準偏差向量的平均向量作為誤差線:
sdmol = c(0.471404521,0,0,5.656854249,16.51934892)
geom_errorbar( aes(x=Site, ymin=mol-sdmol, ymax= mol sdmol), width=0.4, colour="orange", alpha=0.9, size=1) theme(text=element_text(size=20) ))
如果有幫助,我可以重新組合我的所有資料。謝謝!
uj5u.com熱心網友回復:
像這樣的東西?
library(tidyverse)
DF %>%
pivot_longer(
cols = c(mol, an, crust)
) %>%
ggplot(aes(x=factor(Site), y=value, fill=name))
geom_col(position = position_dodge())

或者
library(tidyverse)
DF %>%
pivot_longer(
cols = c(mol, an, crust)
) %>%
ggplot(aes(x=Site, y=value, fill=name))
geom_col(position = position_dodge())
facet_wrap(.~Site, scales = "free")

轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/348080.html
