R语言笔记:群体药动学数据探索

3,486次阅读
20 条评论

用到的包

library(dplyr)
library(ggplot2)
library(gridExtra)

加载资源

source("D:\\工作文档\\R\\col_function.r")

设置工作目录

setwd("C:\\Users\\Administrator.ADMIN-20170618T\\Documents\\demo-data\\PPK\\iv infusion 3cp")

读取数据

#read data----
SDTAB<-read.table("SDTAB1",sep="",skip=1,header = TRUE) 
PKdata<-read.csv("MonkeyPK.csv",header=T,skip=2)

过滤数据

#filter data----
PKdata<-filter(MKPK,MDV==0)
PKdata<-filter(MKPK,C!="C")
INDFIT_PK5<-filter(INDFIT_PK,TIME>829)

单位和分类因子

#add unit----
MKPK$DOSE[MKPK$DOSE==0.5]<-"0.5 mg"
#data group----
MKPK$DOSE_f<-factor(MKPK$DOSE,levels=c("0.5 mg","1.5 mg"))

求均值方差等

#Conc Mean Profile-----
ConcvsTIME<-summarise(group_by(MKPKSAD,TIME,DOSE_f),
                      mean=mean(CONC),
                      sd=sd(CONC),
                      n=sum(!is.na(CONC)),
                      se=sd/sqrt(n))

#---
  ylim(0,500)+
  xlim(0,1200)+
  scale_y_log10()+
  facet_wrap(~DOSE_f,ncol=3)+
  facet_wrap(~ID,ncol=7)+
  guides(color=FALSE)+

  legend.text = element_blank()  
  legend.position="none"
  scale_y_log10(breaks=c(c(0.1,1,10,100,1000)),
              labels=c(0.1,1,10,100,1000))
  scale_x_continuous(breaks=c(c(168,336,504,672,840,1008,1176,1344,1512,1680,1848)),
  labels=c("1","2","3","4","5","6","7","8","9","10","11"))
  scale_y_continuous(limits = c(0,800),
                     breaks = seq(0,800,200))+
    scale_x_continuous(limits = c(2040,2160),
                       breaks = seq(2040,2160,24))+
    scale_colour_manual(name="",
                        breaks=c("10 mg","20 mg","40 mg","10~40 mg"),
    scale_colour_hue(labels=c("0.6 mg/kg","1.2 mg/kg","2 mg/kg","3 mg/kg","4 mg/kg","4.5 mg/kg","5.3 mg/kg","7.1 mg/kg","8 mg/kg","9 mg/kg","16 mg/kg","44.5 mg/kg"))+                       values=c("#ED0000CC","#42B540FF","#00468BCC","black")) +  

#----
CONCSADvsTIME<-
  ggplot(data=ConcvsTIME)+
  geom_point(aes(x=TIME,y=mean,group=factor(DOSE_f),color=factor(DOSE_f)))+
  geom_errorbar(aes(x=TIME,ymin=mean-se,ymax=mean+se,color=factor(DOSE_f),group=factor(DOSE_f)),width=0.5,size=0.7)+
  geom_line(aes(x=TIME,y=mean,color=factor(DOSE_f),group=factor(DOSE_f)),size=0.7)+
  labs(color="",shape="")+
  xlab("Time (h)")+ylab("绝对OD值")+
  # facet_wrap(~DOSE_f)+
  theme_test()+
  theme(axis.text=element_text(size=14,color="black"),
        # axis.text.y=element_text(angle = 90,hjust=0.5),
        axis.title =element_text(size=14),
        panel.border = element_rect(colour = "black", fill=NA, size=0.5))
CONCSADvsTIME
ggsave("CONCSADvsTIME.jpeg", CONCSADvsTIME, width = 6, height = 3)


#----
INDFIT_PK2<-filter(INDFIT_PK,NMT<169)
INDFIT_PK3<-filter(INDFIT_PK,NMT>839)
INDFIT_PK<-ggplot()+
  geom_line(data=INDFIT_PK2,aes(x=NMT,y=mean,color=factor(DOSE_f),group=DOSE_f),size=0.7)+
  geom_line(data=INDFIT_PK3,aes(x=NMT,y=mean,color=factor(DOSE_f),group=DOSE_f),size=0.7)+
  geom_point(data=INDFIT_PK,aes(x=NMT,y=mean,color=factor(DOSE_f)))+
  # geom_errorbar(data=INDFIT_PK,aes(x=NMT,ymin=mean-se,ymax=mean+se,color=factor(DOSE_f)),width=0.4,size=0.7)+
  labs(color="",shape="")+
  xlab("Time(h)")+ylab("Concentration (ug/mL)")+
  # xlim(0,1200)+
  # ylim(0,500)+
  # scale_shape_manual(values = c(4:10))+
  theme_test()+
  theme(axis.text=element_text(size=14,color="black"),
        axis.text.y=element_text(angle = 90,hjust=0.5),
        axis.title =element_text(size=14),
        panel.border = element_rect(colour = "black", fill=NA, size=0.5))
INDFIT_PK
ggsave("CONCprofile.jpeg", INDFIT_PK, width = 6, height = 4)


#----
ConcvsTIME<-filter(ConcvsTIME,TIME!=0)
CONCSADvsTIME3<-
  ggplot(data=filter(MKPKSAD,TIME!=0))+
  geom_point(aes(x=TIME,y=CONC,group=factor(ID),color=factor(DOSE_f)),size=1)+
  geom_line(aes(x=TIME,y=CONC,group=factor(ID),color=factor(DOSE_f)),size=0.5)+
  labs(color="",shape="")+
  xlab("Time (h)")+ylab("Concentration (渭g/mL)")+
  facet_wrap(~DOSE_f,ncol=3)+
  theme_test()+
  theme(axis.text=element_text(size=12,color="black"),
        # axis.text.y=element_text(angle = 90,hjust=0.5),
        axis.title =element_text(size=12),
        panel.border = element_rect(colour = "black", fill=NA, size=0.5),
        legend.position="none")
CONCSADvsTIME3
ggsave("CONCSADvsTIMEGROUP.jpeg", CONCSADvsTIME3, width = 6, height = 3)

#CONC----
INDFIT_PK<-EPOPKMAD1
INDFIT_PK4<-filter(INDFIT_PK,TIME<169)
INDFIT_PK5<-filter(INDFIT_PK,TIME>829)
NDFIT_PK<-ggplot()+
  geom_line(data=INDFIT_PK4,aes(x=TIME,y=CONC,group=DOSE_f,color=factor(DOSE_f)))+
  geom_line(data=INDFIT_PK5,aes(x=TIME,y=CONC,group=DOSE_f,color=factor(DOSE_f)))+
  geom_point(data=INDFIT_PK,aes(x=TIME,y=CONC,color=factor(DOSE_f)),shape=21,fill=NA)+
  facet_wrap(~ID,ncol=7)+
  xlab("\nTime after Dose (h)")+ylab("Concentration (ug/mL)\n")+
  guides(color=FALSE)+
  theme_test()+
  theme(axis.text=element_text(size=10,color="black"),
        # axis.text.y=element_text(angle = 90,hjust=0.5),
        axis.title =element_text(size=14),
        panel.border = element_rect(colour = "black", fill=NA, size=0.5),
        strip.background = element_rect(fill="lightblue",colour = NA),
        strip.text = element_text(size = 12))
NDFIT_PK
ggsave("CONCIDprofile.jpeg", NDFIT_PK, width = 14, height = 8)
正文完
 
评论(20 条评论)
shen
2025-11-24 11:28:19 回复

iv infusion 3cp 大佬可以分享下嘛

 Macintosh  Chrome  中国安徽省淮北市电信
2025-12-07 03:14:58 回复

Your point of view caught my eye and was very interesting. Thanks. I have a question for you.

 Windows  Edge  中国广西玉林市电信
2025-12-22 08:55:36 回复

Thanks for sharing. I read many of your blog posts, cool, your blog is very good. https://www.binance.com/de-CH/register?ref=W0BCQMF1

 Windows  Edge  中国广西玉林市电信
2026-01-26 22:34:33 回复

Thanks for sharing. I read many of your blog posts, cool, your blog is very good.

 Windows  Edge  中国广西玉林市电信
2026-02-18 23:42:48 回复

Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me.

 Windows  Edge  中国广西玉林市电信
2026-02-20 08:18:31 回复

I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article. https://www.binance.info/pt-BR/register?ref=GJY4VW8W

 Windows  Edge  中国广西玉林市电信
2026-03-07 03:35:09 回复

Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me. https://www.binance.com/register?ref=QCGZMHR6

 Windows  Edge  中国广西玉林市电信

I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.

 Windows  Edge  中国广西玉林市电信

Thanks for sharing. I read many of your blog posts, cool, your blog is very good.

 Windows  Edge  中国广西钦州市电信
2026-03-31 06:53:25 回复

Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me?

 Windows  Edge  中国广西玉林市电信
2026-04-19 16:12:38 回复

Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me. https://www.binance.info/ES_la/register?ref=VDVEQ78S

 Windows  Edge  中国广西百色市电信
2026-05-07 10:33:50 回复

Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me?

 Windows  Edge  中国广西玉林市电信
2026-05-10 19:45:46 回复

Your article helped me a lot, is there any more related content? Thanks! https://www.binance.info/register?ref=IXBIAFVY

 Windows  Edge  中国广西钦州市电信
2026-05-11 05:01:51 回复

Thanks for sharing. I read many of your blog posts, cool, your blog is very good. https://accounts.binance.info/da-DK/register?ref=V3MG69RO

 Windows  Edge  中国广西百色市电信

I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.

 Windows  Edge  中国广西玉林市电信
2026-05-16 15:16:24 回复

Your point of view caught my eye and was very interesting. Thanks. I have a question for you.

 Windows  Edge  中国广西玉林市电信

Thanks for sharing. I read many of your blog posts, cool, your blog is very good.

 Windows  Edge  中国广西玉林市电信
2026-05-23 05:59:37 回复

Your article helped me a lot, is there any more related content? Thanks!

 Windows  Edge  中国广西钦州市电信
2026-05-26 06:27:43 回复

Your article helped me a lot, is there any more related content? Thanks!

 Windows  Edge  中国广西钦州市电信
2026-06-12 07:11:57 回复

Your article helped me a lot, is there any more related content? Thanks! https://accounts.binance.bh/id/register?ref=UM6SMJM3

 Windows  Edge  中国广西钦州市电信