我有一個資料框,例如
Seq start end
S1 20 30
S2 25 35
S3 40 45
S4 41 60
S5 20 60
S6 10 30
我想用ggplot創建一個圖形,例如:

我在 X 軸內繪制每個條形坐標的位置。
對 y 軸內的條形順序沒有偏好,但它們不需要重疊。
如果有幫助,這是 dput 資料框
structure(list(Seq = c("S1", "S2", "S3", "S4", "S5", "S6"), start = c(20L,
25L, 40L, 41L, 20L, 10L), end = c(30L, 35L, 45L, 60L, 60L, 30L
)), class = "data.frame", row.names = c(NA, -6L))
uj5u.com熱心網友回復:
與geom_segment:
ggplot(data) geom_segment(aes(x = start,
y = Seq,
xend = end,
yend = Seq),
size = 3)

uj5u.com熱心網友回復:
按序列著色;
示例代碼:
library(ggplot2)
ggplot(df, aes(y = seq, x = start, colour = seq))
geom_segment(aes(yend = seq, xend = end), size = 3)
labs(x = "Position", y="", color="Sequences")
theme_minimal()
陰謀:

樣本資料:
df<-structure(list(seq = c("S1", "S2", "S3", "S4", "S5", "S6"), start = c(20L,
25L, 40L, 41L, 20L, 10L), end = c(30L, 35L, 45L, 60L, 60L, 30L
)), class = "data.frame", row.names = c(NA, -6L))
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/445313.html
上一篇:替換資料框中的相同變數
