我不太清楚如何你想可视化你的数据,但也许是这样的?
library(tidyverse)
df %>%
rowid_to_column("patient") %>%
mutate(patient = factor(patient)) %>%
gather(key, val, -patient) %>%
ggplot(aes(x = key, y = val, colour = patient, group = patient)) +
geom_line()
df %>%
rowid_to_column("patient") %>%
mutate(patient = factor(patient)) %>%
gather(key, val, -patient) %>%
ggplot(aes(x = key, y = val, colour = patient, group = patient)) +
geom_line() +
facet_wrap(~ patient)
样本数据
df <- read.table(text =
" A1 A2 A3 A4 A5
2 2 2 2 2
3 3 3 3 4
3 3 3 3 4
1 1 2 2 1
3 2 2 3 2
4 4 4 3 4", header = T)
要删除 x 轴,您可以这样做
df %>%
rowid_to_column("patient") %>%
mutate(patient = factor(patient)) %>%
gather(key, val, -patient) %>%
ggplot(aes(x = key, y = val, colour = patient, group = patient)) +
geom_line() +
facet_wrap(~ patient) +
theme(
axis.title.x = element_blank(),
axis.text.x = element_blank(),
axis.ticks.x = element_blank())
请注意,移除 x 轴可能不太明智。