我有一个如下所示的数据框:
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 ……
我不是很清楚 怎么样 你想要想象你的数据,但也许是这样的?
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轴可能不是很明智。