我正在使用以下代码,并希望在图例或图表上的某个位置显示每次访问的唯一Subject
(数据集中的变量)的计数。
#All Subjects on one plot
ggplot(data=PKData, aes(x=NewTime, y=Concentration, colour=factor(Sub)))+
scale_colour_manual(name=" ",values = c("1"="blue", "2"="red"),
labels=c("Cycle1", "Cycle4"))+
#stat_summary(aes(y = SUBJECT, group = Visit), fun.y=count, colour="red", geom="line")+
ggtitle("Concentration time plot")+
geom_line(aes(group=sub1), size=1) +
theme(plot.title=element_text(family="Times", face="bold", size=10))+
theme(axis.title.y = element_text(size = 13, angle = 90, face="bold"))+
theme(axis.title.x = element_text(size = 13, angle = 00, face="bold"))+
theme_bw()+
theme(plot.background = element_blank(),panel.grid.major = element_blank()
,panel.grid.minor = element_blank()) +
labs(x="Time", y="Venetoclax Concentration (ng/mL)")+
scale_x_discrete(labels=c("1"="C1D1 Pre", "2"="C1D1 Post", "3"="C4D1 Pre", "4"= "C4D1 Post"))+
ggsave("AllSubjects.pdf",width=12,height=8)
Subject Visit Time_Text Concentration NewTime Sub sub1
11000 Cycle1 PRE 84.6 1 1 1
11000 Cycle1 POST 344 2 1 1
11000 Cycle4 PRE 172 3 2 2
11000 Cycle4 POST 858 4 2 2
11050 Cycle1 PRE 855 2 1 3
11050 Cyce4 POST 168 3 2 4
11050 Cyce4 POST 581 4 2 4
11051 Cycle1 PRE 380 1 1 5
11051 Cycle1 PRE 1500 2 1 5
11051 Cycle4 POST 372 3 2 6
11051 Cycle4 POST 876 4 2 6
11058 Cycle1 PRE 1540 1 1 7
11058 Cycle1 POST 1940 2 1 7
11058 Cycle4 PRE 1520 3 2 8
11058 Cycle4 POST 3290 4 2 8