我有 100 個人,每個人都有一個變數的 3 個點(在 0、6 和 12 個月之后)。我在 Time = 0 時按變數升序對它們進行了排序,并為此使用了向量“c”。
PatID pDC_of_lymphocytes_percentage Time c
2 001-502 0.000 0 1
3 001-502 0.051 6 1
1 001-502 0.880 12 1
19 001-518 0.000 0 2
20 001-518 0.250 6 2
21 001-518 0.210 12 2
87 021-503 0.000 0 3
86 021-503 0.350 6 3
85 021-503 1.510 12 3
104 025-501 0.000 0 4
103 025-501 0.030 6 4
105 025-501 0.000 12 4
現在我嘗試為它們中的每一個繪制線圖,但線圖應該是:
- 按從最低到最高起始值的順序
- 一張圖中總是多條線(例如 10 條線)
我嘗試過使用 pull 函式,但它只在每個圖中繪制了一條線,因為一次只提取了 1 個 ID。
pdf(paste("pDCoflymphocytespercentage.pdf",sep = ""), width = 15)
l_ply(pDC.frame.plot %>% distinct(PatID) %>% pull(), function(patID) {
patDF <- pDC.frame.plot %>% filter(PatID == patID)
patDF$Time <- as.numeric(patDF$Time)
print(
ggplot(patDF, aes(x=Time))
geom_line(aes(y=pDC_of_lymphocytes_percentage, linetype="solid", group=1),colour = "steelblue",size=2,name="")
scale_linetype(name="")
)
)
}, .progress = "text")
dev.off()
任何解決方案如何在一個圖表中獲得多個線圖,每個 PatID 在時間 0、6、12 有一個?
提前致謝。
uj5u.com熱心網友回復:
這是你想要的?
library(ggplot2)
df<- tibble::tribble(
~PatID, ~pDC_of_lymphocytes_percentage, ~Time,
"001-502", 0.000, 0,
"001-502", 0.051, 6,
"001-502", 0.880, 12,
"001-518", 0.000, 0,
"001-518", 0.250, 6,
"001-518", 0.210, 12,
"021-503", 0.000, 0,
"021-503", 0.350, 6,
"021-503", 1.510, 12,
"025-501", 0.000, 0,
"025-501", 0.030, 6,
"025-501", 0.000, 12
)
df |>
ggplot(aes(x = Time, y = pDC_of_lymphocytes_percentage))
geom_line()
facet_wrap(~PatID)

使用reprex v2.0.2創建于 2022-10-26
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/523462.html
上一篇:識別R中多個自變數的閾值
