cairo_pdf("dataAnalyticsExample06052025.pdf", width = 8, height = 6,family = "SimHei" ) library(readr) library(data.table) library(Cairo) library(ggplot2) library(stringr) library(datetime) library(dplyr) library(ggthemes) #guess_encoding("historyRecord20.csv") # [[1]]$encoding df2 <- fread("historyRecord20250604175205UTF.csv",encoding = "UTF-8",fill = TRUE) df2$批次名称<-as.character(df2$批次名称) df2<-df2[!is.na(df2$批次名称),] df2$是否阳性<-df2$结论 df2$是否阳性[df2$是否阳性=="阳性"]<-1.0 df2$是否阳性[df2$是否阳性=="阴性"]<-0.0 df2$是否阳性[df2$是否阳性=="无效"]<-0.5 df2$是否阳性<-as.numeric(df2$是否阳性) df2$是否阳性[is.na(df2$是否阳性)]<-0.5 df2$结论[df2$结论=="阳性"]<-1.0 df2$结论[df2$结论=="阴性"]<-0.0 df2$结论<-as.numeric(df2$结论) df2$是否有效<-1 df2$是否有效[df2$是否阳性==0.5]<-0 summary(df2$结论) summary(df2$是否阳性) summary(df2$是否有效) #df2$仪器序列号_批次名称<-str_c(df2$仪器序列号,'_',df2$批次名称) colnames(df2) #df200<-df20 summary(df2$仪器序列号) summary(df2$批次名称) unique(df2$批次名称) unique(df2$仪器序列号) unique(df2$省市编号) unique(df2$详细地址) unique(df2$仪器投放区域) unique(df2$仪器备注名称) df20<-df2 #[,c(1:11,16,17,20)] df20$省市编号<-str_c("省市编号: ",df20$省市编号) colnames(df20) # df20$testTime<-str_sub(df20$测试时间,1,19) # df20$date<-as.Date(str_sub(df20$测试时间,1,10)) # df20$time<-str_sub(df20$测试时间,12,19) # df20$time0<-as.time(df20$time) df20$testMonth<-str_sub(df20$测试时间,1,7) #df20$testMonthinNumber<-as.numeric(str_c(str_sub(df20$测试时间,1,4),str_sub(df20$测试时间,6,7))) df20$testDay<-as.Date(str_sub(df20$测试时间,1,10)) df20$testTime<-as.datetime(str_sub(df20$测试时间,1,19),format='%Y-%m-%d %H:%M:%S') duration<-difftime(max(df20$testTime,na.rm = TRUE),min(df20$testTime,na.rm = TRUE),unit="hour")/24 df20$testTimeFromeBegining<-as.numeric(difftime(df20$testTime,min(df20$testTime,na.rm = TRUE),unit="hour")/24) summary(df20$testTimeFromeBegining) dayMax<-max(df20$testTimeFromeBegining) df20<-df20[dayMax-df20$testTimeFromeBegining<730,] #unique(df20$仪器序列号_批次名称) df20 <- df20[order(df20$批次名称,df20$testTimeFromeBegining),] running_avg <- function(x, window = 3) { sapply(seq_along(x), function(i) { start <- max(1, i - window + 1) mean(x[start:i],na.rm=TRUE) }) } lumping_avg<- function(x) { sapply(seq_along(x), function(i) { mean(x[1:i],na.rm=TRUE) }) } lumping_sd<- function(x) { sapply(seq_along(x), function(i) { sd(x[1:i],na.rm=TRUE) }) } df20$浓度1<-as.numeric(df20$浓度1) df20$C值<-as.numeric(df20$C值) df20$T值<-as.numeric(df20$T值) df20$ToverC值<-df20$T值/df20$C值 df20$ToverC值[df20$是否有效==0]<-NA summary(as.numeric(df20$结论)) summary(df20$浓度1) summary(df20$ToverC值) summary(df20$testTimeFromeBegining) colnames(df20) df20 <- df20[order(df20$testTimeFromeBegining),] df20 <- df20 %>% group_by(批次名称) %>% transform( 浓度1移动均值 = running_avg(浓度1,20), C值移动均值 = running_avg(C值,20), T值移动均值 = running_avg(T值,20), ToverC值移动均值 = running_avg(ToverC值,20), 结论移动均值 = running_avg(结论,20) ) # df20$浓度1移动均值<-running_avg(df20$浓度1, 20) # df20$C值移动均值<-running_avg(df20$C值, 20) # df20$T值移动均值<-running_avg(df20$T值, 20) # df20$ToverC值移动均值<-running_avg(df20$ToverC值, 20) # df20$结论移动均值<-running_avg(df20$结论, 20) df20$浓度1累计均值<-lumping_avg(df20$浓度1) df20$C值累计均值<-lumping_avg(df20$C值) df20$T值累计均值<-lumping_avg(df20$T值) df20$ToverC值累计均值<-lumping_avg(df20$ToverC值) df20$结论累计均值<-lumping_avg(df20$结论) # df20$浓度1累计标差<-lumping_sd(df20$浓度1) # df20$C值累计标差<-lumping_sd(df20$C值) # df20$T值累计标差<-lumping_sd(df20$T值) # df20$ToverC值累计标差<-lumping_sd(df20$ToverC值) # df20$结论累计标差<-lumping_sd(df20$结论移动均值) df20$浓度1累计标差<-lumping_sd(df20$浓度1移动均值) df20$C值累计标差<-lumping_sd(df20$C值移动均值) df20$T值累计标差<-lumping_sd(df20$T值移动均值) df20$ToverC值累计标差<-lumping_sd(df20$ToverC值移动均值) df20$结论累计标差<-lumping_sd(df20$结论移动均值) df20$浓度1允许波动范围<-df20$浓度1累计均值+2*df20$浓度1累计标差 df20$C值允许波动范围<-df20$C值累计均值+2*df20$C值累计标差 df20$T值允许波动范围<-df20$T值累计均值+2*df20$T值累计标差 df20$ToverC值允许波动范围<-df20$ToverC值累计均值+2*df20$ToverC值累计标差 df20$结论允许波动范围<-df20$结论累计均值+2*df20$结论累计标差 summary(df20$浓度1移动均值) summary(df20$running_avg) summary(df20$浓度1累计均值) summary(df20$浓度1累计标差) summary(df20$结论累计均值) dfByDayAndLocation <- df20 %>% group_by(testDay,testMonth,省市编号) %>% summarise( 测试数 = n(), 阳性数=sum(结论,na.rm = TRUE), 有效数=sum(是否有效,na.rm = TRUE), 仪器数=length(unique(仪器序列号)), 批次数=length(unique(批次名称)), ) dfByDayAndLocation$阳性率<-dfByDayAndLocation$阳性数/dfByDayAndLocation$有效数 dfByDayAndLocation$有效率<-dfByDayAndLocation$有效数/dfByDayAndLocation$测试数 dfByDayAndLocation$阳性数<-as.integer(dfByDayAndLocation$阳性数) dfByDayAndLocation$测试数<-as.integer(dfByDayAndLocation$测试数) dfByDayAndLocation$有效数<-as.integer(dfByDayAndLocation$有效数) dfByDayAndLocation <- dfByDayAndLocation[order(dfByDayAndLocation$testDay),] lastDay<-last(dfByDayAndLocation$testDay) dfByDayAndLocation<-dfByDayAndLocation[lastDay-dfByDayAndLocation$testDay<=21,] dfByMonthAndLocation <- df20 %>% group_by(testMonth,省市编号) %>% summarise( 测试数 = n(), 阳性数=sum(结论,na.rm = TRUE), 有效数=sum(是否有效,na.rm = TRUE), 仪器数=length(unique(仪器序列号)), 批次数=length(unique(批次名称)), ) dfByMonthAndLocation$阳性率<-dfByMonthAndLocation$阳性数/dfByMonthAndLocation$有效数 dfByMonthAndLocation$有效率<-dfByMonthAndLocation$有效数/dfByMonthAndLocation$测试数 dfByMonthAndLocation$阳性数<-as.integer(dfByMonthAndLocation$阳性数) dfByMonthAndLocation$测试数<-as.integer(dfByMonthAndLocation$测试数) dfByMonthAndLocation$有效数<-as.integer(dfByMonthAndLocation$有效数) dfByMonthAndLocation <- dfByMonthAndLocation[order(dfByMonthAndLocation$testMonth),] dfByMonth <- df20 %>% group_by(testMonth) %>% summarise( 测试数 = n(), 阳性数=sum(结论,na.rm = TRUE), 有效数=sum(是否有效,na.rm = TRUE), 仪器数=length(unique(仪器序列号)), 批次数=length(unique(批次名称)), 区域数=length(unique(省市编号)) ) dfByMonth$阳性率<-dfByMonth$阳性数/dfByMonth$有效数 dfByMonth$有效率<-dfByMonth$有效数/dfByMonth$测试数 dfByMonth$阳性数<-as.integer(dfByMonth$阳性数) dfByMonth$测试数<-as.integer(dfByMonth$测试数) dfByMonth$有效数<-as.integer(dfByMonth$有效数) dfByMonth$区域数<-as.integer(dfByMonth$区域数) dfByMonth <- dfByMonth[order(dfByMonth$testMonth),] dfBy区域 <- df20 %>% group_by(省市编号) %>% summarise( 仪器数=length(unique(仪器序列号)), 批次数=length(unique(批次名称)), 测试数 = n(), 阳性数=sum(结论,na.rm = TRUE), 有效数=sum(是否有效,na.rm = TRUE), 区域开始 = min(testTimeFromeBegining,na.rm = TRUE), 区域截止 = max(testTimeFromeBegining,na.rm = TRUE) ) dfBy区域$阳性率<-dfBy区域$阳性数/dfBy区域$有效数 dfBy区域$有效率<-dfBy区域$有效数/dfBy区域$测试数 dfBy区域$阳性数<-as.integer(dfBy区域$阳性数) dfBy区域$测试数<-as.integer(dfBy区域$测试数) dfBy区域$有效数<-as.integer(dfBy区域$有效数) dfBy批次 <- df20 %>% group_by(批次名称) %>% summarise( 仪器数=length(unique(仪器序列号)), 测试数 = n(), 阳性数=sum(结论,na.rm = TRUE), 有效数=sum(是否有效,na.rm = TRUE), 批次开始 = min(testTimeFromeBegining,na.rm = TRUE), 批次截止 = max(testTimeFromeBegining,na.rm = TRUE), 区域数=length(unique(省市编号)) ) dfBy批次$阳性率<-dfBy批次$阳性数/dfBy批次$有效数 dfBy批次$有效率<-dfBy批次$有效数/dfBy批次$测试数 dfBy批次$阳性数<-as.integer(dfBy批次$阳性数) dfBy批次$测试数<-as.integer(dfBy批次$测试数) dfBy批次$有效数<-as.integer(dfBy批次$有效数) dfBy批次$区域数<-as.integer(dfBy批次$区域数) dfBy仪器 <- df20 %>% group_by(仪器序列号) %>% summarise( 批次数=length(unique(批次名称)), 测试数 = n(), 阳性数=sum(结论,na.rm = TRUE), 有效数=sum(是否有效,na.rm = TRUE), 批次开始 = min(testTimeFromeBegining,na.rm = TRUE), 批次截止 = max(testTimeFromeBegining,na.rm = TRUE), 区域数=length(unique(省市编号)) ) dfBy仪器$阳性率<-dfBy仪器$阳性数/dfBy仪器$有效数 dfBy仪器$有效率<-dfBy仪器$有效数/dfBy仪器$测试数 dfBy仪器$阳性数<-as.integer(dfBy仪器$阳性数) dfBy仪器$测试数<-as.integer(dfBy仪器$测试数) dfBy仪器$有效数<-as.integer(dfBy仪器$有效数) dfBy仪器$区域数<-as.integer(dfBy仪器$区域数) dfByDayAndLocation测试数<-cbind("测试数",dfByDayAndLocation[,c(1:3,4)]) dfByDayAndLocation有效数<-cbind("有效数",dfByDayAndLocation[,c(1:3,6)]) dfByDayAndLocation阳性数<-cbind("阳性数",dfByDayAndLocation[,c(1:3,5)]) colnames(dfByDayAndLocation测试数)<-c("group","Day","Month", "省市编号", "count") colnames(dfByDayAndLocation有效数)<-c("group","Day","Month", "省市编号", "count") colnames(dfByDayAndLocation阳性数)<-c("group","Day","Month", "省市编号", "count") dfByDayAndLocationNumber<-rbind(rbind(dfByDayAndLocation测试数,dfByDayAndLocation有效数),dfByDayAndLocation阳性数) #dfByDayAndLocationNumber$省市编号<-str_c("省市编号: ",dfByDayAndLocationNumber$省市编号) dfByDayNumber <- dfByDayAndLocationNumber %>% group_by(group,Day,Month) %>% summarise( count=sum(count,na.rm = TRUE)) dfByDayAndLocation <- df20 %>% group_by(testDay,testMonth,省市编号) %>% summarise( 测试数 = n(), 阳性数=sum(结论,na.rm = TRUE), 有效数=sum(是否有效,na.rm = TRUE), 仪器数=length(unique(仪器序列号)), 批次数=length(unique(批次名称)), ) dfByDayAndLocation$阳性率<-dfByDayAndLocation$阳性数/dfByDayAndLocation$有效数 dfByDayAndLocation$有效率<-dfByDayAndLocation$有效数/dfByDayAndLocation$测试数 dfByDayAndLocation$阳性数<-as.integer(dfByDayAndLocation$阳性数) dfByDayAndLocation$测试数<-as.integer(dfByDayAndLocation$测试数) dfByDayAndLocation$有效数<-as.integer(dfByDayAndLocation$有效数) dfByDayAndLocation <- dfByDayAndLocation[order(dfByDayAndLocation$testDay),] lastDay<-last(dfByDayAndLocation$testDay) dfByDayAndLocation<-dfByDayAndLocation[lastDay-dfByDayAndLocation$testDay<=21,] dfByDay <- df20 %>% group_by(testMonth,testDay) %>% summarise( 测试数 = n(), 阳性数=sum(结论,na.rm = TRUE), 有效数=sum(是否有效,na.rm = TRUE), 仪器数=length(unique(仪器序列号)), 批次数=length(unique(批次名称)), 区域数=length(unique(省市编号)) ) dfByDay$阳性率<-dfByDay$阳性数/dfByDay$有效数 dfByDay$有效率<-dfByDay$有效数/dfByDay$测试数 dfByDay$阳性数<-as.integer(dfByDay$阳性数) dfByDay$测试数<-as.integer(dfByDay$测试数) dfByDay$有效数<-as.integer(dfByDay$有效数) dfByDay$区域数<-as.integer(dfByDay$区域数) dfByDay <- dfByDay[order(dfByDay$testDay),] dfByDay<-dfByDay[lastDay-dfByDay$testDay<=21,] dfByDayAndLocation测试数<-cbind("测试数",dfByDayAndLocation[,c(1:3,4)]) dfByDayAndLocation有效数<-cbind("有效数",dfByDayAndLocation[,c(1:3,6)]) dfByDayAndLocation阳性数<-cbind("阳性数",dfByDayAndLocation[,c(1:3,5)]) colnames(dfByDayAndLocation测试数)<-c("group","Day","Month", "省市编号", "count") colnames(dfByDayAndLocation有效数)<-c("group","Day","Month", "省市编号", "count") colnames(dfByDayAndLocation阳性数)<-c("group","Day","Month", "省市编号", "count") dfByDayAndLocationNumber<-rbind(rbind(dfByDayAndLocation测试数,dfByDayAndLocation有效数),dfByDayAndLocation阳性数) #dfByDayAndLocationNumber$省市编号<-str_c("省市编号: ",dfByDayAndLocationNumber$省市编号) dfByDayNumber <- dfByDayAndLocationNumber %>% group_by(group,Day,Month) %>% summarise( count=sum(count,na.rm = TRUE)) dfByDayAndLocation有效率<-cbind("有效率",dfByDayAndLocation[,c(1,2,3,10)]) dfByDayAndLocation阳性率<-cbind("阳性率",dfByDayAndLocation[,c(1,2,3,9)]) colnames(dfByDayAndLocation有效率)<-c("group","Day","Month", "省市编号", "Ratio") colnames(dfByDayAndLocation阳性率)<-c("group","Day","Month", "省市编号", "Ratio") dfByDayAndLocationRatio<-rbind(dfByDayAndLocation有效率,dfByDayAndLocation阳性率) #dfByDayAndLocationRatio$省市编号<-str_c("省市编号: ",dfByDayAndLocationRatio$省市编号) dfByDay有效率<-cbind("有效率",dfByDay[,c(1,2,10)]) dfByDay阳性率<-cbind("阳性率",dfByDay[,c(1,2,9)]) colnames(dfByDay有效率)<-c("group","Month","Day","Ratio") colnames(dfByDay阳性率)<-c("group","Month","Day","Ratio") dfByDayRatio<-rbind(dfByDay有效率,dfByDay阳性率) dfByDayAndLocation仪器数<-cbind("仪器数",dfByDayAndLocation[,c(1,2,3,7)]) dfByDayAndLocation批次数<-cbind("批次数",dfByDayAndLocation[,c(1,2,3,8)]) colnames(dfByDayAndLocation仪器数)<-c("group","Day","Month", "省市编号", "Count") colnames(dfByDayAndLocation批次数)<-c("group","Day","Month", "省市编号", "Count") dfByDayAndLocationCount<-rbind(dfByDayAndLocation仪器数,dfByDayAndLocation批次数) #dfByDayAndLocationCount$省市编号<-str_c("省市编号: ",dfByDayAndLocationCount$省市编号) dfByDay仪器数<-cbind("仪器数",dfByDay[,c(1,2,6)]) dfByDay批次数<-cbind("批次数",dfByDay[,c(1,2,7)]) dfByDay区域数<-cbind("区域数",dfByDay[,c(1,2,8)]) colnames(dfByDay仪器数)<-c("group","Month","Day","count") colnames(dfByDay批次数)<-c("group","Month","Day","count") colnames(dfByDay区域数)<-c("group","Month","Day","count") dfByDayCount<-rbind(rbind(dfByDay仪器数,dfByDay批次数),dfByDay区域数) dfByMonthAndLocation测试数<-cbind("测试数",dfByMonthAndLocation[,c(1,2,3)]) dfByMonthAndLocation有效数<-cbind("有效数",dfByMonthAndLocation[,c(1,2,5)]) dfByMonthAndLocation阳性数<-cbind("阳性数",dfByMonthAndLocation[,c(1,2,4)]) colnames(dfByMonthAndLocation测试数)<-c("group","month","省市编号", "count") colnames(dfByMonthAndLocation有效数)<-c("group","month","省市编号", "count") colnames(dfByMonthAndLocation阳性数)<-c("group","month","省市编号", "count") dfByMonthAndLocationNumber<-rbind(rbind(dfByMonthAndLocation测试数,dfByMonthAndLocation有效数),dfByMonthAndLocation阳性数) #dfByMonthAndLocationNumber$省市编号<-str_c("省市编号: ",dfByMonthAndLocationNumber$省市编号) dfByMonthNumber <- dfByMonthAndLocationNumber %>% group_by(group,month) %>% summarise( count=sum(count,na.rm = TRUE)) dfByMonthAndLocation有效率<-cbind("有效率",dfByMonthAndLocation[,c(1,2,9)]) dfByMonthAndLocation阳性率<-cbind("阳性率",dfByMonthAndLocation[,c(1,2,8)]) colnames(dfByMonthAndLocation有效率)<-c("group","month","省市编号", "Ratio") colnames(dfByMonthAndLocation阳性率)<-c("group","month","省市编号", "Ratio") dfByMonthAndLocationRatio<-rbind(dfByMonthAndLocation有效率,dfByMonthAndLocation阳性率) #dfByMonthAndLocationRatio$省市编号<-str_c("省市编号: ",dfByMonthAndLocationRatio$省市编号) dfByMonth有效率<-cbind("有效率",dfByMonth[,c(1,9)]) dfByMonth阳性率<-cbind("阳性率",dfByMonth[,c(1,8)]) colnames(dfByMonth有效率)<-c("group","month","Ratio") colnames(dfByMonth阳性率)<-c("group","month","Ratio") dfByMonthRatio<-rbind(dfByMonth有效率,dfByMonth阳性率) dfByMonthAndLocation仪器数<-cbind("仪器数",dfByMonthAndLocation[,c(1,2,6)]) dfByMonthAndLocation批次数<-cbind("批次数",dfByMonthAndLocation[,c(1,2,7)]) colnames(dfByMonthAndLocation仪器数)<-c("group","month","省市编号", "Count") colnames(dfByMonthAndLocation批次数)<-c("group","month","省市编号", "Count") dfByMonthAndLocationCount<-rbind(dfByMonthAndLocation仪器数,dfByMonthAndLocation批次数) #dfByMonthAndLocationCount$省市编号<-str_c("省市编号: ",dfByMonthAndLocationCount$省市编号) dfByMonth仪器数<-cbind("仪器数",dfByMonth[,c(1,5)]) dfByMonth批次数<-cbind("批次数",dfByMonth[,c(1,6)]) dfByMonth区域数<-cbind("区域数",dfByMonth[,c(1,7)]) colnames(dfByMonth仪器数)<-c("group","month","count") colnames(dfByMonth批次数)<-c("group","month","count") colnames(dfByMonth区域数)<-c("group","month","count") dfByMonthCount<-rbind(rbind(dfByMonth仪器数,dfByMonth批次数),dfByMonth区域数) dfby区域Number <- dfByMonthAndLocationNumber %>% group_by(group,省市编号) %>% summarise( count=sum(count,na.rm = TRUE)) dfBy区域有效率<-cbind("有效率",dfBy区域[,c(1,10)]) dfBy区域阳性率<-cbind("阳性率",dfBy区域[,c(1,9)]) colnames(dfBy区域有效率)<-c("group","区域","Ratio") colnames(dfBy区域阳性率)<-c("group","区域","Ratio") dfBy区域Ratio<-rbind(dfBy区域有效率,dfBy区域阳性率) #dfBy区域Ratio$区域<-str_c("省市编号: ",dfBy区域Ratio$区域) dfBy区域仪器数<-cbind("仪器数",dfBy区域[,c(1,2)]) dfBy区域批次数<-cbind("批次数",dfBy区域[,c(1,3)]) colnames(dfBy区域仪器数)<-c("group","区域","count") colnames(dfBy区域批次数)<-c("group","区域","count") dfBy区域Count<-rbind(dfBy区域仪器数,dfBy区域批次数) #dfBy区域Count$区域<-str_c("省市编号: ",dfBy区域Count$区域) dfBy区域开始<-cbind("区域开始",dfBy区域[,c(1,7)]) dfBy区域截止<-cbind("区域截止",dfBy区域[,c(1,8)]) colnames(dfBy区域开始)<-c("group","区域","time") colnames(dfBy区域截止)<-c("group","区域","time") dfBy区域time<-rbind(dfBy区域开始,dfBy区域截止) #dfBy区域time$区域<-str_c("省市编号: ",dfBy区域time$区域) dfBy批次测试数<-cbind("测试数",dfBy批次[,c(1,3)]) dfBy批次有效数<-cbind("有效数",dfBy批次[,c(1,5)]) dfBy批次阳性数<-cbind("阳性数",dfBy批次[,c(1,4)]) colnames(dfBy批次测试数)<-c("group","批次","count") colnames(dfBy批次有效数)<-c("group","批次","count") colnames(dfBy批次阳性数)<-c("group","批次","count") dfBy批次Number<-rbind(dfBy批次测试数,rbind(dfBy批次有效数,dfBy批次阳性数)) dfBy批次有效率<-cbind("有效率",dfBy批次[,c(1,10)]) dfBy批次阳性率<-cbind("阳性率",dfBy批次[,c(1,9)]) colnames(dfBy批次有效率)<-c("group","批次","Ratio") colnames(dfBy批次阳性率)<-c("group","批次","Ratio") dfBy批次Ratio<-rbind(dfBy批次有效率,dfBy批次阳性率) dfBy批次仪器数<-cbind("仪器数",dfBy批次[,c(1,2)]) dfBy批次区域数<-cbind("区域数",dfBy批次[,c(1,8)]) colnames(dfBy批次仪器数)<-c("group","批次","count") colnames(dfBy批次区域数)<-c("group","批次","count") dfBy批次Count<-rbind(dfBy批次仪器数,dfBy批次区域数) dfBy批次开始<-cbind("批次开始",dfBy批次[,c(1,6)]) dfBy批次截止<-cbind("批次截止",dfBy批次[,c(1,7)]) colnames(dfBy批次开始)<-c("group","批次","time") colnames(dfBy批次截止)<-c("group","批次","time") dfBy批次time<-rbind(dfBy批次开始,dfBy批次截止) dfBy仪器测试数<-cbind("测试数",dfBy仪器[,c(1,3)]) dfBy仪器有效数<-cbind("有效数",dfBy仪器[,c(1,5)]) dfBy仪器阳性数<-cbind("阳性数",dfBy仪器[,c(1,4)]) colnames(dfBy仪器测试数)<-c("group","仪器","count") colnames(dfBy仪器有效数)<-c("group","仪器","count") colnames(dfBy仪器阳性数)<-c("group","仪器","count") dfBy仪器Number<-rbind(dfBy仪器测试数,rbind(dfBy仪器有效数,dfBy仪器阳性数)) dfBy仪器有效率<-cbind("有效率",dfBy仪器[,c(1,10)]) dfBy仪器阳性率<-cbind("阳性率",dfBy仪器[,c(1,9)]) colnames(dfBy仪器有效率)<-c("group","仪器","Ratio") colnames(dfBy仪器阳性率)<-c("group","仪器","Ratio") dfBy仪器Ratio<-rbind(dfBy仪器有效率,dfBy仪器阳性率) dfBy仪器批次数<-cbind("批次数",dfBy仪器[,c(1,2)]) dfBy仪器区域数<-cbind("区域数",dfBy仪器[,c(1,8)]) colnames(dfBy仪器批次数)<-c("group","仪器","count") colnames(dfBy仪器区域数)<-c("group","仪器","count") dfBy仪器Count<-rbind(dfBy仪器批次数,dfBy仪器区域数) dfBy仪器开始<-cbind("仪器开始",dfBy仪器[,c(1,6)]) dfBy仪器截止<-cbind("仪器截止",dfBy仪器[,c(1,7)]) colnames(dfBy仪器开始)<-c("group","仪器","time") colnames(dfBy仪器截止)<-c("group","仪器","time") dfBy仪器time<-rbind(dfBy仪器开始,dfBy仪器截止) dfBy区域top4<-dfBy区域$省市编号[order(-dfBy区域$测试数)][1:4] dfBy区域top4<-dfBy区域top4[!is.na(dfBy区域top4)] dfBy批次top4<-dfBy批次$批次名称[order(-dfBy批次$测试数)][1:4] dfBy批次top4<-dfBy批次top4[!is.na(dfBy批次top4)] dfBy仪器top4<-dfBy仪器$仪器序列号[order(-dfBy仪器$测试数)][1:4] dfBy仪器top4<-dfBy仪器top4[!is.na(dfBy仪器top4)] df20Top4区域<-df20[df20$省市编号 %in% dfBy区域top4,] df20Top4批次<-df20[df20$批次名称 %in% dfBy批次top4,] df20Top4仪器<-df20[df20$仪器序列号 %in% dfBy仪器top4,] df20Top4区域$省市编号<-factor(df20Top4区域$省市编号,levels = dfBy区域top4) df20Top4批次$批次名称<-factor(df20Top4批次$批次名称,levels = dfBy批次top4) df20Top4仪器$仪器序列号<-factor(df20Top4仪器$仪器序列号,levels = dfBy仪器top4) dfByDayAndLocationNumber<-dfByDayAndLocationNumber[dfByDayAndLocationNumber$省市编号 %in% dfBy区域top4,] dfByDayAndLocationNumber$省市编号<-factor(dfByDayAndLocationNumber$省市编号,levels = dfBy区域top4) dfByDayAndLocationCount<-dfByDayAndLocationCount[dfByDayAndLocationCount$省市编号 %in% dfBy区域top4,] dfByDayAndLocationCount$省市编号<-factor(dfByDayAndLocationCount$省市编号,levels = dfBy区域top4) dfByDayAndLocationRatio<-dfByDayAndLocationRatio[dfByDayAndLocationRatio$省市编号 %in% dfBy区域top4,] dfByDayAndLocationRatio$省市编号<-factor(dfByDayAndLocationRatio$省市编号,levels = dfBy区域top4) dfByMonthAndLocationRatio<-dfByMonthAndLocationRatio[dfByMonthAndLocationRatio$省市编号 %in% dfBy区域top4,] dfByMonthAndLocationRatio$省市编号<-factor(dfByMonthAndLocationRatio$省市编号,levels = dfBy区域top4) dfByMonthAndLocationCount<-dfByMonthAndLocationCount[dfByMonthAndLocationCount$省市编号 %in% dfBy区域top4,] dfByMonthAndLocationCount$省市编号<-factor(dfByMonthAndLocationCount$省市编号,levels = dfBy区域top4) dfByMonthAndLocationNumber<-dfByMonthAndLocationNumber[dfByMonthAndLocationNumber$省市编号 %in% dfBy区域top4,] dfByMonthAndLocationNumber$省市编号<-factor(dfByMonthAndLocationNumber$省市编号,levels = dfBy区域top4) #dfByDayNumber1<-dfByDayNumber[dfByDayNumber$Month=="2024-09",] plotdfByDayNumber<-ggplot(dfByDayNumber, aes(x = Day, y = count, fill = group)) + # geom_bar(stat="identity", # position = position_dodge() # ) + geom_col( position = position_dodge(width = 0.4), # 控制条间距 width = 0.7 # 条宽度 ) + geom_line( aes(group = group, color = group), position = position_dodge(width = 0.4), size = 1, linetype="dashed", show.legend=FALSE, alpha = 1.0 ) + scale_color_manual(values = c("red", "blue","green")) + # 自定义颜色 # geom_point( # aes(color = group), # position = position_dodge(width = 0.4), # size = 3 # ) + geom_text( aes(label = count), # 标签内容 position = position_dodge(width = 0.4), # 与柱子位置一致 vjust = -0.4, # 垂直位置(负值向上) color = "black", # 标签颜色 size = 1.2 # 字体大小 ) + # geom_text(aes(label=count),vjust=1.6,size=1,color="white")+ labs( title = "最后三周按日测试统计", x = "测试时间", y = "统计数值", fill = "" ) + scale_fill_manual(values = c("red", "blue","green")) + # 自定义颜色 theme_minimal() + theme( plot.title = element_text(size = 14, face = "bold", hjust = 0.5), axis.title.x = element_text(size = 12, face = "bold"), axis.title.y = element_text(size = 12, face = "bold"), axis.text.x = element_text(size = 8, face = "bold",angle=90) , legend.position = "right") plotdfByDayNumber plotdfByDayLocationNumber<-ggplot(dfByDayAndLocationNumber, aes(x = Day, y = count, fill = group)) + geom_col( position = position_dodge(width = 0.4), # 控制条间距 width = 0.7 # 条宽度 ) + geom_line( aes(group = group, color = group), position = position_dodge(width = 0.4), size = 1, linetype="dashed", show.legend=FALSE, alpha = 1.0 ) + scale_color_manual(values = c("red", "blue","green")) + # 自定义颜色 # geom_point( # aes(color = group), # position = position_dodge(width = 0.4), # size = 3 # ) + geom_text( aes(label = count), # 标签内容 position = position_dodge(width = 0.4), # 与柱子位置一致 vjust = -0.4, # 垂直位置(负值向上) color = "black", # 标签颜色 size = 1.2 # 字体大小 ) + facet_wrap( ~ 省市编号,ncol=2) + labs( title = "最后三周按日按地区测试统计", x = "测试时间", y = "数值统计", fill = "" ) + scale_fill_manual(values = c("red", "blue","green")) + # 自定义颜色 theme_minimal() + theme( plot.title = element_text(size = 14, face = "bold", hjust = 0.5), axis.title.x = element_text(size = 12,face = "bold"), axis.title.y = element_text(size = 12,face = "bold"), axis.text.x = element_text(size = 8, face = "bold",angle=90) , panel.border = element_rect( color = "black", # 边框颜色 size = 1., # 边框粗细 linetype = "solid", # 线型(solid/dashed/dotted) fill = NA # 填充色(NA为透明) ), legend.position = "right") plotdfByDayLocationNumber plotdfByDayRatio<-ggplot(dfByDayRatio, aes(x = Day, y = Ratio, fill = group)) + # geom_bar(stat="identity", # position = position_dodge() # ) + geom_col( position = position_dodge(width = 0.4), # 控制条间距 width = 0.7 # 条宽度 ) + geom_line( aes(group = group, color = group), position = position_dodge(width = 0.4), size = 1, linetype="dashed", show.legend=FALSE, alpha = 1.0 ) + scale_color_manual(values = c("red", "green")) + # 自定义颜色 # geom_point( # aes(color = group), # position = position_dodge(width = 0.4), # size = 3 # ) + geom_text( aes(label = round(Ratio,2)), # 标签内容 position = position_dodge(width = 0.4), # 与柱子位置一致 vjust = -0.4, # 垂直位置(负值向上) color = "black", # 标签颜色 size = 1.2 # 字体大小 ) + # geom_text(aes(label=Ratio),vjust=1.6,size=1,color="white")+ labs( title = "最后三周按日测试统计", x = "测试时间", y = "统计数值", fill = "" ) + scale_fill_manual(values = c("red","green")) + # 自定义颜色 theme_minimal() + theme( plot.title = element_text(size = 14, face = "bold", hjust = 0.5), axis.title.x = element_text(size = 12,face = "bold"), axis.title.y = element_text(size = 12,face = "bold"), axis.text.x = element_text(size = 8, face = "bold",angle=90) , legend.position = "right") plotdfByDayRatio plotdfByDayLocationRatio<-ggplot(dfByDayAndLocationRatio, aes(x = Day, y = Ratio, fill = group)) + geom_col( position = position_dodge(width = 0.4), # 控制条间距 width = 0.7 # 条宽度 ) + geom_line( aes(group = group, color = group), position = position_dodge(width = 0.4), size = 1, linetype="dashed", show.legend=FALSE, alpha = 1.0 ) + scale_color_manual(values = c("red", "green")) + # 自定义颜色 # geom_point( # aes(color = group), # position = position_dodge(width = 0.4), # size = 3 # ) + geom_text( aes(label = round(Ratio,2)), # 标签内容 position = position_dodge(width = 0.4), # 与柱子位置一致 vjust = -0.4, # 垂直位置(负值向上) color = "black", # 标签颜色 size = 1.2 # 字体大小 ) + facet_wrap( ~ 省市编号,ncol=2) + labs( title = "最后三周按日按地区测试统计", x = "测试时间", y = "统计数值", fill = "" ) + scale_fill_manual(values = c("red", "green")) + # 自定义颜色 theme_minimal() + theme( plot.title = element_text(size = 14, face = "bold", hjust = 0.5), axis.title.x = element_text(size = 12,face = "bold"), axis.title.y = element_text(size = 12,face = "bold"), axis.text.x = element_text(size = 8, face = "bold",angle=90) , panel.border = element_rect( color = "black", # 边框颜色 size = 1., # 边框粗细 linetype = "solid", # 线型(solid/dashed/dotted) fill = NA # 填充色(NA为透明) ), legend.position = "right") plotdfByDayLocationRatio plotdfByDayCount<-ggplot(dfByDayCount, aes(x = Day, y = count, fill = group)) + # geom_bar(stat="identity", # position = position_dodge() # ) + geom_col( position = position_dodge(width = 0.4), # 控制条间距 width = 0.7 # 条宽度 ) + geom_line( aes(group = group, color = group), position = position_dodge(width = 0.4), size = 1, linetype="dashed", show.legend=FALSE, alpha = 1.0 ) + scale_color_manual(values = c("red", "blue","green")) + # 自定义颜色 # geom_point( # aes(color = group), # position = position_dodge(width = 0.4), # size = 3 # ) + geom_text( aes(label = count), # 标签内容 position = position_dodge(width = 0.4), # 与柱子位置一致 vjust = -0.4, # 垂直位置(负值向上) color = "black", # 标签颜色 size = 1.2 # 字体大小 ) + # geom_text(aes(label=count),vjust=1.6,size=1,color="white")+ labs( title = "最后三周按日测试统计", x = "测试时间", y = "统计数值", fill = "" ) + scale_fill_manual(values = c("red", "blue","green")) + # 自定义颜色 theme_minimal() + theme( plot.title = element_text(size = 14, face = "bold", hjust = 0.5), axis.title.x = element_text(size = 12,face = "bold"), axis.title.y = element_text(size = 12,face = "bold"), axis.text.x = element_text(size = 8, face = "bold",angle=90) , legend.position = "right") plotdfByDayCount plotdfByDayLocationCount<-ggplot(dfByDayAndLocationCount, aes(x = Day, y = Count, fill = group)) + geom_col( position = position_dodge(width = 0.4), # 控制条间距 width = 0.7 # 条宽度 ) + geom_line( aes(group = group, color = group), position = position_dodge(width = 0.4), size = 1, linetype="dashed", show.legend=FALSE, alpha = 1.0 ) + scale_color_manual(values = c("red","green")) + # 自定义颜色 # geom_point( # aes(color = group), # position = position_dodge(width = 0.4), # size = 3 # ) + geom_text( aes(label = Count), # 标签内容 position = position_dodge(width = 0.4), # 与柱子位置一致 vjust = -0.4, # 垂直位置(负值向上) color = "black", # 标签颜色 size = 1.2 # 字体大小 ) + facet_wrap( ~ 省市编号,ncol=2) + labs( title = "最后三周按日按地区统计", x = "测试时间", y = "统计数值", fill = "" ) + scale_fill_manual(values = c("red", "green")) + # 自定义颜色 theme_minimal() + theme( plot.title = element_text(size = 14, face = "bold", hjust = 0.5), axis.title.x = element_text(size = 12,face = "bold"), axis.title.y = element_text(size = 12,face = "bold"), axis.text.x = element_text(size = 8, face = "bold",angle=90) , panel.border = element_rect( color = "black", # 边框颜色 size = 1., # 边框粗细 linetype = "solid", # 线型(solid/dashed/dotted) fill = NA # 填充色(NA为透明) ), legend.position = "right") plotdfByDayLocationCount plotdfByMonthNumber<-ggplot(dfByMonthNumber, aes(x = month, y = count, fill = group)) + # geom_bar(stat="identity", # position = position_dodge() # ) + geom_col( position = position_dodge(width = 0.4), # 控制条间距 width = 0.7 # 条宽度 ) + geom_line( aes(group = group, color = group), position = position_dodge(width = 0.4), size = 1, linetype="dashed", show.legend=FALSE, alpha = 1.0 ) + scale_color_manual(values = c("red", "blue","green")) + # 自定义颜色 # geom_point( # aes(color = group), # position = position_dodge(width = 0.4), # size = 3 # ) + geom_text( aes(label = count), # 标签内容 position = position_dodge(width = 0.4), # 与柱子位置一致 vjust = -0.4, # 垂直位置(负值向上) color = "black", # 标签颜色 size = 1.2 # 字体大小 ) + labs( title = "每月测试统计", x = "测试时间", y = "统计数值", fill = "" ) + scale_fill_manual(values = c("red", "blue","green")) + # 自定义颜色 theme_minimal() + theme( plot.title = element_text(size = 14, face = "bold", hjust = 0.5), axis.title.x = element_text(size = 12,face = "bold"), axis.title.y = element_text(size = 12,face = "bold"), axis.text.x = element_text(size = 8, face = "bold",angle=90) , legend.position = "right") plotdfByMonthNumber plotdfByMonthLocationNumber<-ggplot(dfByMonthAndLocationNumber, aes(x = month, y = count, fill = group)) + geom_col( position = position_dodge(width = 0.4), # 控制条间距 width = 0.7 # 条宽度 ) + geom_line( aes(group = group, color = group), position = position_dodge(width = 0.4), size = 1, linetype="dashed", show.legend=FALSE, alpha = 1.0 ) + scale_color_manual(values = c("red", "blue","green")) + # 自定义颜色 # geom_point( # aes(color = group), # position = position_dodge(width = 0.4), # size = 3 # ) + geom_text( aes(label = count), # 标签内容 position = position_dodge(width = 0.4), # 与柱子位置一致 vjust = -0.4, # 垂直位置(负值向上) color = "black", # 标签颜色 size = 1.2 # 字体大小 ) + facet_wrap( ~ 省市编号,ncol=2) + labs( title = "每月分区测试统计", x = "测试时间", y = "数值统计", fill = "" ) + scale_fill_manual(values = c("red", "blue","green")) + # 自定义颜色 theme_minimal() + theme( plot.title = element_text(size = 14, face = "bold", hjust = 0.5), axis.title.x = element_text(size = 12,face = "bold"), axis.title.y = element_text(size = 12,face = "bold"), axis.text.x = element_text(size = 8, face = "bold",angle=90) , panel.border = element_rect( color = "black", # 边框颜色 size = 1., # 边框粗细 linetype = "solid", # 线型(solid/dashed/dotted) fill = NA # 填充色(NA为透明) ), legend.position = "right") plotdfByMonthLocationNumber plotdfByMonthRatio<-ggplot(dfByMonthRatio, aes(x = month, y = Ratio, fill = group)) + # geom_bar(stat="identity", # position = position_dodge() # ) + geom_col( position = position_dodge(width = 0.4), # 控制条间距 width = 0.7 # 条宽度 ) + geom_line( aes(group = group, color = group), position = position_dodge(width = 0.4), size = 1, linetype="dashed", show.legend=FALSE, alpha = 1.0 ) + scale_color_manual(values = c("red", "green")) + # 自定义颜色 # geom_point( # aes(color = group), # position = position_dodge(width = 0.4), # size = 3 # ) + geom_text( aes(label = round(Ratio,2)), # 标签内容 position = position_dodge(width = 0.4), # 与柱子位置一致 vjust = -0.4, # 垂直位置(负值向上) color = "black", # 标签颜色 size = 1.2 # 字体大小 ) + # geom_text(aes(label=Ratio),vjust=1.6,size=1,color="white")+ labs( title = "每月测试统计", x = "测试时间", y = "统计数值", fill = "" ) + scale_fill_manual(values = c("red","green")) + # 自定义颜色 theme_minimal() + theme( plot.title = element_text(size = 14, face = "bold", hjust = 0.5), axis.title.x = element_text(size = 12,face = "bold"), axis.title.y = element_text(size = 12,face = "bold"), axis.text.x = element_text(size = 8, face = "bold",angle=90) , legend.position = "right") plotdfByMonthRatio plotdfByMonthLocationRatio<-ggplot(dfByMonthAndLocationRatio, aes(x = month, y = Ratio, fill = group)) + geom_col( position = position_dodge(width = 0.4), # 控制条间距 width = 0.7 # 条宽度 ) + geom_line( aes(group = group, color = group), position = position_dodge(width = 0.4), size = 1, linetype="dashed", show.legend=FALSE, alpha = 1.0 ) + scale_color_manual(values = c("red", "green")) + # 自定义颜色 # geom_point( # aes(color = group), # position = position_dodge(width = 0.4), # size = 3 # ) + geom_text( aes(label = round(Ratio,2)), # 标签内容 position = position_dodge(width = 0.4), # 与柱子位置一致 vjust = -0.4, # 垂直位置(负值向上) color = "black", # 标签颜色 size = 1.2 # 字体大小 ) + facet_wrap( ~ 省市编号,ncol=2) + labs( title = "每月分区测试统计", x = "测试时间", y = "统计数值", fill = "" ) + scale_fill_manual(values = c("red", "green")) + # 自定义颜色 theme_minimal() + theme( plot.title = element_text(size = 14, face = "bold", hjust = 0.5), axis.title.x = element_text(size = 12,face = "bold"), axis.title.y = element_text(size = 12,face = "bold"), axis.text.x = element_text(size = 8, face = "bold",angle=90) , panel.border = element_rect( color = "black", # 边框颜色 size = 1., # 边框粗细 linetype = "solid", # 线型(solid/dashed/dotted) fill = NA # 填充色(NA为透明) ), legend.position = "right") plotdfByMonthLocationRatio plotdfByMonthCount<-ggplot(dfByMonthCount, aes(x = month, y = count, fill = group)) + # geom_bar(stat="identity", # position = position_dodge() # ) + geom_col( position = position_dodge(width = 0.4), # 控制条间距 width = 0.7 # 条宽度 ) + geom_line( aes(group = group, color = group), position = position_dodge(width = 0.4), size = 1, linetype="dashed", show.legend=FALSE, alpha = 1.0 ) + scale_color_manual(values = c("red", "blue","green")) + # 自定义颜色 # geom_point( # aes(color = group), # position = position_dodge(width = 0.4), # size = 3 # ) + geom_text( aes(label = count), # 标签内容 position = position_dodge(width = 0.4), # 与柱子位置一致 vjust = -0.4, # 垂直位置(负值向上) color = "black", # 标签颜色 size = 1.2 # 字体大小 ) + # geom_text(aes(label=count),vjust=1.6,size=1,color="white")+ labs( title = "每月测试统计", x = "测试时间", y = "统计数值", fill = "" ) + scale_fill_manual(values = c("red", "blue","green")) + # 自定义颜色 theme_minimal() + theme( plot.title = element_text(size = 14, face = "bold", hjust = 0.5), axis.title.x = element_text(size = 12,face = "bold"), axis.title.y = element_text(size = 12,face = "bold"), axis.text.x = element_text(size = 8, face = "bold",angle=90) , legend.position = "right") plotdfByMonthCount plotdfByMonthLocationCount<-ggplot(dfByMonthAndLocationCount, aes(x = month, y = Count, fill = group)) + geom_col( position = position_dodge(width = 0.4), # 控制条间距 width = 0.7 # 条宽度 ) + geom_line( aes(group = group, color = group), position = position_dodge(width = 0.4), size = 1, linetype="dashed", show.legend=FALSE, alpha = 1.0 ) + scale_color_manual(values = c("red","green")) + # 自定义颜色 # geom_point( # aes(color = group), # position = position_dodge(width = 0.4), # size = 3 # ) + geom_text( aes(label = Count), # 标签内容 position = position_dodge(width = 0.4), # 与柱子位置一致 vjust = -0.8, # 垂直位置(负值向上) color = "black", # 标签颜色 size = 2.0 # 字体大小 ) + facet_wrap( ~ 省市编号,ncol=2) + labs( title = "每月分区测试统计", x = "测试时间", y = "统计数值", fill = "" ) + scale_fill_manual(values = c("red", "green")) + # 自定义颜色 theme_minimal() + theme( plot.title = element_text(size = 14, face = "bold", hjust = 0.5), axis.title.x = element_text(size = 12,face = "bold"), axis.title.y = element_text(size = 12,face = "bold"), axis.text.x = element_text(size = 8, face = "bold",angle=90) , panel.border = element_rect( color = "black", # 边框颜色 size = 1., # 边框粗细 linetype = "solid", # 线型(solid/dashed/dotted) fill = NA # 填充色(NA为透明) ), legend.position = "right") plotdfByMonthLocationCount plotdfby区域Number<-ggplot(dfby区域Number, aes(x = 省市编号, y = count, fill = group)) + # geom_bar(stat="identity", # position = position_dodge() # ) + geom_col( position = position_dodge(width = 0.4), # 控制条间距 width = 0.7 # 条宽度 ) + geom_line( aes(group = group, color = group), position = position_dodge(width = 0.4), size = 1, linetype="dashed", show.legend=FALSE, alpha = 1.0 ) + scale_color_manual(values = c("red", "blue","green")) + # 自定义颜色 # geom_point( # aes(color = group), # position = position_dodge(width = 0.4), # size = 3 # ) + geom_text( aes(label = count), # 标签内容 position = position_dodge(width = 0.4), # 与柱子位置一致 vjust = -0.4, # 垂直位置(负值向上) color = "black", # 标签颜色 size = 1.2 # 字体大小 ) + # geom_text(aes(label=count),vjust=1.6,size=1,color="white")+ labs( title = "分区测试统计", x = "测试区域", y = "统计数值", fill = "" ) + scale_fill_manual(values = c("red", "blue","green")) + # 自定义颜色 theme_minimal() + theme( plot.title = element_text(size = 14, face = "bold", hjust = 0.5), axis.title.x = element_text(size = 12,face = "bold"), axis.title.y = element_text(size = 12,face = "bold"), axis.text.x = element_text(size = 8, face = "bold",angle=90) , legend.position = "right") plotdfby区域Number plotdfBy区域Ratio<-ggplot(dfBy区域Ratio, aes(x = 区域, y = Ratio, fill = group)) + # geom_bar(stat="identity", # position = position_dodge() # ) + geom_col( position = position_dodge(width = 0.4), # 控制条间距 width = 0.7 # 条宽度 ) + geom_line( aes(group = group, color = group), position = position_dodge(width = 0.4), size = 1, linetype="dashed", show.legend=FALSE, alpha = 1.0 ) + scale_color_manual(values = c("red", "green")) + # 自定义颜色 # geom_point( # aes(color = group), # position = position_dodge(width = 0.4), # size = 3 # ) + geom_text( aes(label = round(Ratio,2)), # 标签内容 position = position_dodge(width = 0.4), # 与柱子位置一致 vjust = -0.8, # 垂直位置(负值向上) color = "black", # 标签颜色 size = 2.0 # 字体大小 ) + labs( title = "分区测试统计", x = "测试区域", y = "统计数值", fill = "" ) + scale_fill_manual(values = c("red","green")) + # 自定义颜色 theme_minimal() + theme( plot.title = element_text(size = 14, face = "bold", hjust = 0.5), axis.title.x = element_text(size = 12,face = "bold"), axis.title.y = element_text(size = 12,face = "bold"), axis.text.x = element_text(size = 8, face = "bold",angle=90) , legend.position = "right") plotdfBy区域Ratio plotdfBy区域Count<-ggplot(dfBy区域Count, aes(x = 区域, y = count, fill = group)) + # geom_bar(stat="identity", # position = position_dodge() # ) + geom_col( position = position_dodge(width = 0.4), # 控制条间距 width = 0.7 # 条宽度 ) + geom_line( aes(group = group, color = group), position = position_dodge(width = 0.4), size = 1, linetype="dashed", show.legend=FALSE, alpha = 1.0 ) + scale_color_manual(values = c("red", "green")) + # 自定义颜色 # geom_point( # aes(color = group), # position = position_dodge(width = 0.4), # size = 3 # ) + geom_text( aes(label = count), # 标签内容 position = position_dodge(width = 0.4), # 与柱子位置一致 vjust = -0.8, # 垂直位置(负值向上) color = "black", # 标签颜色 size = 2.0 # 字体大小 ) + labs( title = "分区测试统计", x = "测试区域", y = "统计数值", fill = "" ) + scale_fill_manual(values = c("red", "green")) + # 自定义颜色 theme_minimal() + theme( plot.title = element_text(size = 14, face = "bold", hjust = 0.5), axis.title.x = element_text(size = 12,face = "bold"), axis.title.y = element_text(size = 12,face = "bold"), axis.text.x = element_text(size = 8, face = "bold",angle=90) , legend.position = "right") plotdfBy区域Count if(FALSE) { plotdfBy区域timeBox <- ggplot(df20, aes(x=省市编号, y=testDay,color=省市编号)) + geom_boxplot(show.legend = FALSE)+ # geom_text(aes(label=count),vjust=1.6,size=1,color="white")+ labs( title = "分区测试时间统计", x = "测试区域", y = "测试时间", fill = "" ) + theme_minimal() + theme( plot.title = element_text(size = 14, face = "bold", hjust = 0.5), axis.title.x = element_text(size = 12, face = "bold"), axis.title.y = element_text(size = 12, face = "bold"), axis.text.x = element_text(size = 8, face = "bold",angle=90) , legend.position = "right") plotdfBy区域timeBox } plotdfBy批次Number<-ggplot(dfBy批次Number, aes(x = 批次, y = count, fill = group)) + # geom_bar(stat="identity", # position = position_dodge() # ) + geom_line( aes(group = group, color = group), position = position_dodge(width = 0.4), size = 1, linetype="dashed", show.legend=FALSE, alpha = 1.0 ) + scale_color_manual(values = c("red", "blue","green")) + # 自定义颜色 # geom_point( # aes(color = group), # position = position_dodge(width = 0.4), # size = 3 # ) + geom_col( position = position_dodge(width = 0.4), # 控制条间距 width = 0.7 # 条宽度 ) + geom_text( aes(label = count), # 标签内容 position = position_dodge(width = 0.4), # 与柱子位置一致 vjust = -0.4, # 垂直位置(负值向上) color = "black", # 标签颜色 size = 1.2 # 字体大小 ) + labs( title = "试剂分批测试统计", x = "测试批次", y = "统计数值", fill = "" ) + scale_fill_manual(values = c("red", "blue","green")) + # 自定义颜色 theme_minimal() + theme( plot.title = element_text(size = 14, face = "bold", hjust = 0.5), axis.title.x = element_text(size = 12,face = "bold"), axis.title.y = element_text(size = 12,face = "bold"), axis.text.x = element_text(size = 8, face = "bold",angle=90) , legend.position = "right") plotdfBy批次Number plotdfBy批次Ratio<-ggplot(dfBy批次Ratio, aes(x = 批次, y = Ratio, fill = group)) + # geom_bar(stat="identity", # position = position_dodge() # ) + geom_col( position = position_dodge(width = 0.4), # 控制条间距 width = 0.7 # 条宽度 ) + geom_line( aes(group = group, color = group), position = position_dodge(width = 0.4), size = 1, linetype="dashed", show.legend=FALSE, alpha = 1.0 ) + scale_color_manual(values = c("red", "green")) + # 自定义颜色 # geom_point( # aes(color = group), # position = position_dodge(width = 0.4), # size = 3 # ) + geom_text( aes(label = round(Ratio,2)), # 标签内容 position = position_dodge(width = 0.4), # 与柱子位置一致 vjust = -0.8, # 垂直位置(负值向上) color = "black", # 标签颜色 size = 2.0 # 字体大小 ) + labs( title = "试剂分批测试统计", x = "测试批次", y = "统计数值", fill = "" ) + scale_fill_manual(values = c("red","green")) + # 自定义颜色 theme_minimal() + theme( plot.title = element_text(size = 14, face = "bold", hjust = 0.5), axis.title.x = element_text(size = 12,face = "bold"), axis.title.y = element_text(size = 12,face = "bold"), axis.text.x = element_text(size = 8, face = "bold",angle=90) , legend.position = "right") plotdfBy批次Ratio plotdfBy批次Count<-ggplot(dfBy批次Count, aes(x = 批次, y = count, fill = group)) + # geom_bar(stat="identity",区域 # position = position_dodge() # ) + geom_col( position = position_dodge(width = 0.4), # 控制条间距 width = 0.7 # 条宽度 ) + geom_line( aes(group = group, color = group), position = position_dodge(width = 0.4), size = 1, linetype="dashed", show.legend=FALSE, alpha = 1.0 ) + scale_color_manual(values = c("red","green")) + # 自定义颜色 # geom_point( # aes(color = group), # position = position_dodge(width = 0.4), # size = 3 # ) + geom_text( aes(label = count), # 标签内容 position = position_dodge(width = 0.4), # 与柱子位置一致 vjust = -0.6, # 垂直位置(负值向上) color = "black", # 标签颜色 size = 2.0 # 字体大小 ) + labs( title = "试剂分批测试统计", x = "测试批次", y = "统计数值", fill = "" ) + scale_fill_manual(values = c("red", "green")) + # 自定义颜色 theme_minimal() + theme( plot.title = element_text(size = 14, face = "bold", hjust = 0.5), axis.title.x = element_text(size = 12,face = "bold"), axis.title.y = element_text(size = 12,face = "bold"), axis.text.x = element_text(size = 8, face = "bold",angle=90) , legend.position = "right") plotdfBy批次Count plotdfBy批次timeBox <- ggplot(df20, aes(x=批次名称, y=testDay,color=批次名称)) + geom_boxplot(show.legend = FALSE)+ # geom_text(aes(label=count),vjust=1.6,size=1,color="white")+ labs( title = "试剂分批时间统计", x = "批次名称", y = "测试时间", fill = "" ) + theme_minimal() + theme( plot.title = element_text(size = 14, face = "bold", hjust = 0.5), axis.title.x = element_text(size = 12, face = "bold"), axis.title.y = element_text(size = 12, face = "bold"), axis.text.x = element_text(size = 8, face = "bold",angle=90) , legend.position = "right") plotdfBy批次timeBox plotdfBy仪器Number<-ggplot(dfBy仪器Number, aes(x = 仪器, y = count, fill = group)) + # geom_bar(stat="identity", # position = position_dodge() # ) + geom_col( position = position_dodge(width = 0.4), # 控制条间距 width = 0.7 # 条宽度 ) + geom_line( aes(group = group, color = group), position = position_dodge(width = 0.4), size = 1, linetype="dashed", show.legend=FALSE, alpha = 1.0 ) + scale_color_manual(values = c("red", "blue","green")) + # 自定义颜色 # geom_point( # aes(color = group), # position = position_dodge(width = 0.4), # size = 3 # ) + geom_text( aes(label = count), # 标签内容 position = position_dodge(width = 0.4), # 与柱子位置一致 vjust = -0.4, # 垂直位置(负值向上) color = "black", # 标签颜色 size = 1.2 # 字体大小 ) + # geom_text(aes(label=count),vjust=1.6,size=1,color="white")+ labs( title = "仪器测试统计", x = "测试仪器", y = "统计数值", fill = "" ) + scale_fill_manual(values = c("red", "blue","green")) + # 自定义颜色 theme_minimal() + theme( plot.title = element_text(size = 14, face = "bold", hjust = 0.5), axis.title.x = element_text(size = 12,face = "bold"), axis.title.y = element_text(size = 12,face = "bold"), axis.text.x = element_text(size = 8, face = "bold",angle=90) , legend.position = "right") plotdfBy仪器Number plotdfBy仪器Ratio<-ggplot(dfBy仪器Ratio, aes(x = 仪器, y = Ratio, fill = group)) + # geom_bar(stat="identity", # position = position_dodge() # ) + geom_col( position = position_dodge(width = 0.4), # 控制条间距 width = 0.7 # 条宽度 ) + geom_line( aes(group = group, color = group), position = position_dodge(width = 0.4), size = 1, linetype="dashed", show.legend=FALSE, alpha = 1.0 ) + scale_color_manual(values = c("red","green")) + # 自定义颜色 # geom_point( # aes(color = group), # position = position_dodge(width = 0.4), # size = 3 # ) + geom_text( aes(label = round(Ratio,2)), # 标签内容 position = position_dodge(width = 0.4), # 与柱子位置一致 vjust = -0.8, # 垂直位置(负值向上) color = "black", # 标签颜色 size = 2.0 # 字体大小 ) + labs( title = "仪器测试统计", x = "测试仪器", y = "统计数值", fill = "" ) + scale_fill_manual(values = c("red","green")) + # 自定义颜色 theme_minimal() + theme( plot.title = element_text(size = 14, face = "bold", hjust = 0.5), axis.title.x = element_text(size = 12,face = "bold"), axis.title.y = element_text(size = 12,face = "bold"), axis.text.x = element_text(size = 8, face = "bold",angle=90) , legend.position = "right") plotdfBy仪器Ratio plotdfBy仪器Count<-ggplot(dfBy仪器Count, aes(x = 仪器, y = count, fill = group)) + # geom_bar(stat="identity",区域 # position = position_dodge() # ) + geom_col( position = position_dodge(width = 0.4), # 控制条间距 width = 0.7 # 条宽度 ) + geom_line( aes(group = group, color = group), position = position_dodge(width = 0.4), size = 1, linetype="dashed", show.legend=FALSE, alpha = 1.0 ) + scale_color_manual(values = c("red","green")) + # 自定义颜色 # geom_point( # aes(color = group), # position = position_dodge(width = 0.4), # size = 3 # ) + geom_text( aes(label = count), # 标签内容 position = position_dodge(width = 0.4), # 与柱子位置一致 vjust = -0.8, # 垂直位置(负值向上) color = "black", # 标签颜色 size = 2.0 # 字体大小 ) + # geom_text(aes(label=count),vjust=1.6,size=1,color="white")+ labs( title = "仪器测试统计", x = "测试仪器", y = "统计数值", fill = "" ) + scale_fill_manual(values = c("red", "green")) + # 自定义颜色 theme_minimal() + theme( plot.title = element_text(size = 14, face = "bold", hjust = 0.5), axis.title.x = element_text(size = 12,face = "bold"), axis.title.y = element_text(size = 12,face = "bold"), axis.text.x = element_text(size = 8, face = "bold",angle=90) , legend.position = "right") plotdfBy仪器Count plotdfBy仪器timeBox <- ggplot(df20, aes(x=仪器序列号, y=testDay,color=仪器序列号)) + geom_boxplot(show.legend = FALSE)+ # geom_text(aes(label=count),vjust=1.6,size=1,color="white")+ labs( title = "仪器测试时间统计", x = "仪器名称/序列号", y = "测试时间", fill = "" ) + theme_minimal() + theme( plot.title = element_text(size = 14, face = "bold", hjust = 0.5), axis.title.x = element_text(size = 12, face = "bold"), axis.title.y = element_text(size = 12, face = "bold"), axis.text.x = element_text(size = 8, face = "bold",angle=90) , legend.position = "right") plotdfBy仪器timeBox plot浓度1批次Box <- ggplot(df20, aes(x=批次名称, y=浓度1,color=省市编号)) + geom_boxplot()+ # geom_text(aes(label=count),vjust=1.6,size=1,color="white")+ labs( title = "浓度与试剂批次关系统计", x = "批次名称", y = "浓度1", fill = "" ) + theme_minimal() + theme( plot.title = element_text(size = 14, face = "bold", hjust = 0.5), axis.title.x = element_text(size = 12, face = "bold"), axis.title.y = element_text(size = 12, face = "bold"), axis.text.x = element_text(size = 8, face = "bold",angle=90) , legend.position = "right") plot浓度1批次Box plot浓度1仪器Box <- ggplot(df20, aes(x=仪器序列号, y=浓度1,color=省市编号)) + geom_boxplot()+ # geom_text(aes(label=count),vjust=1.6,size=1,color="white")+ labs( title = "浓度与仪器关系统计", x = "仪器名称/序列号", y = "浓度1", fill = "" ) + theme_minimal() + theme( plot.title = element_text(size = 14, face = "bold", hjust = 0.5), axis.title.x = element_text(size = 12, face = "bold"), axis.title.y = element_text(size = 12, face = "bold"), axis.text.x = element_text(size = 8, face = "bold",angle=90) , legend.position = "right") plot浓度1仪器Box plotC值批次Box <- ggplot(df20, aes(x=批次名称, y=C值,color=省市编号)) + geom_boxplot()+ scale_y_log10()+ # geom_text(aes(label=count),vjust=1.6,size=1,color="white")+ labs( title = "C值与试剂批次关系统计", x = "批次名称", y = "C值", fill = "" ) + theme_minimal() + theme( plot.title = element_text(size = 14, face = "bold", hjust = 0.5), axis.title.x = element_text(size = 12, face = "bold"), axis.title.y = element_text(size = 12, face = "bold"), axis.text.x = element_text(size = 8, face = "bold",angle=90) , legend.position = "right") plotC值批次Box plotC值仪器Box <- ggplot(df20, aes(x=仪器序列号, y=C值,color=省市编号)) + geom_boxplot()+ scale_y_log10()+ # geom_text(aes(label=count),vjust=1.6,size=1,color="white")+ labs( title = "C值与仪器关系统计", x = "仪器名称/序列号", y = "C值", fill = "" ) + theme_minimal() + theme( plot.title = element_text(size = 14, face = "bold", hjust = 0.5), axis.title.x = element_text(size = 12, face = "bold"), axis.title.y = element_text(size = 12, face = "bold"), axis.text.x = element_text(size = 8, face = "bold",angle=90) , legend.position = "right") plotC值仪器Box plotT值批次Box <- ggplot(df20, aes(x=批次名称, y=T值,color=省市编号)) + geom_boxplot()+ scale_y_log10()+ # geom_text(aes(label=count),vjust=1.6,size=1,color="white")+ labs( title = "T值与试剂批次关系统计", x = "批次名称", y = "T值", fill = "" ) + theme_minimal() + theme( plot.title = element_text(size = 14, face = "bold", hjust = 0.5), axis.title.x = element_text(size = 12, face = "bold"), axis.title.y = element_text(size = 12, face = "bold"), axis.text.x = element_text(size = 8, face = "bold",angle=90) , legend.position = "right") plotT值批次Box plotT值仪器Box <- ggplot(df20, aes(x=仪器序列号, y=T值,color=省市编号)) + geom_boxplot()+ scale_y_log10()+ # geom_text(aes(label=count),vjust=1.6,size=1,color="white")+ labs( title = "T值与仪器关系统计", x = "仪器名称/序列号", y = "T值", fill = "" ) + theme_minimal() + theme( plot.title = element_text(size = 14, face = "bold", hjust = 0.5), axis.title.x = element_text(size = 12, face = "bold"), axis.title.y = element_text(size = 12, face = "bold"), axis.text.x = element_text(size = 8, face = "bold",angle=90) , legend.position = "right") plotT值仪器Box plotToverC值批次Box <- ggplot(df20, aes(x=批次名称, y=ToverC值,color=省市编号)) + geom_boxplot()+ # geom_text(aes(label=count),vjust=1.6,size=1,color="white")+ labs( title = "T/C值与试剂批次关系统计", x = "批次名称", y = "T/C值", fill = "" ) + theme_minimal() + theme( plot.title = element_text(size = 14, face = "bold", hjust = 0.5), axis.title.x = element_text(size = 12, face = "bold"), axis.title.y = element_text(size = 12, face = "bold"), axis.text.x = element_text(size = 8, face = "bold",angle=90) , legend.position = "right") plotToverC值批次Box plotToverC值仪器Box <- ggplot(df20, aes(x=仪器序列号, y=ToverC值,color=省市编号)) + geom_boxplot()+ # geom_text(aes(label=count),vjust=1.6,size=1,color="white")+ labs( title = "T/C值与仪器关系统计", x = "仪器名称/序列号", y = "T/C值", fill = "" ) + theme_minimal() + theme( plot.title = element_text(size = 14, face = "bold", hjust = 0.5), axis.title.x = element_text(size = 12, face = "bold"), axis.title.y = element_text(size = 12, face = "bold"), axis.text.x = element_text(size = 8, face = "bold",angle=90) , legend.position = "right") plotToverC值仪器Box plot结论移动均值批次Box <- ggplot(df20, aes(x=批次名称, y=结论移动均值,color=省市编号)) + geom_boxplot()+ # geom_text(aes(label=count),vjust=1.6,size=1,color="white")+ labs( title = "阳性率与试剂批次关系统计", x = "批次名称", y = "结论移动均值", fill = "" ) + theme_minimal() + theme( plot.title = element_text(size = 14, face = "bold", hjust = 0.5), axis.title.x = element_text(size = 12, face = "bold"), axis.title.y = element_text(size = 12, face = "bold"), axis.text.x = element_text(size = 8, face = "bold",angle=90) , legend.position = "right") plot结论移动均值批次Box plot结论移动均值仪器Box <- ggplot(df20, aes(x=仪器序列号, y=结论移动均值,color=省市编号)) + geom_boxplot()+ # geom_text(aes(label=count),vjust=1.6,size=1,color="white")+ labs( title = "阳性率与仪器关系统计", x = "仪器名称/序列号", y = "结论移动均值", fill = "" ) + theme_minimal() + theme( plot.title = element_text(size = 14, face = "bold", hjust = 0.5), axis.title.x = element_text(size = 12, face = "bold"), axis.title.y = element_text(size = 12, face = "bold"), axis.text.x = element_text(size = 8, face = "bold",angle=90) , legend.position = "right") plot结论移动均值仪器Box xmin<-min(df20$testDay) xmax<-max(df20$testDay) ymax<-max(6,quantile(df20$浓度1,probs = 0.95, # 要计算的百分位(0-1之间) na.rm = TRUE)) plot浓度1by批次 <- ggplot(df20)+geom_point(aes(testDay, 浓度1,color=as.character(批次名称)))+ geom_line(aes(testDay,浓度1移动均值),color="blue")+ geom_line(aes(testDay,浓度1累计均值),color="green",linewidth=1.)+ geom_line(aes(testDay,浓度1允许波动范围),color="red",linewidth=1.)+ xlim(xmin, xmax) + ylim(0, ymax)+theme(legend.position ="right")+ labs( title = "浓度", # 主标题 x = "测试日期", # X轴标签 y = "浓度1", # Y轴标签 color = "批次名称" # 图例标题 )+ scale_x_date( date_labels = "%Y-%m-%d", # 格式符组合 date_breaks = "1 month" # 标签间隔(如 "2 weeks") )+ theme_minimal() + theme( plot.title = element_text(size = 14, face = "bold", hjust = 0.5), axis.title.x = element_text(size = 10,face = "bold"), axis.title.y = element_text(size = 10,face = "bold"), axis.text.x = element_text(size = 8, face = "bold",angle=90), legend.position = "right") plot浓度1by批次 plot浓度1批次<-ggplot(df20Top4批次)+geom_point(aes(testDay, 浓度1),color="orange")+ geom_line(aes(testDay,浓度1移动均值),color="blue")+ geom_line(aes(testDay,浓度1累计均值),color="green",linewidth=1.)+ geom_line(aes(testDay,浓度1允许波动范围),color="red",linewidth=1.)+ facet_wrap( ~ 批次名称,ncol=2) + labs( title = "浓度与试剂批次关系", # 主标题 x = "测试日期", # X轴标签 y = "浓度1" )+ scale_fill_manual(values = c("red", "green")) + # 自定义颜色 theme_minimal() + theme( plot.title = element_text(size = 14, face = "bold", hjust = 0.5), axis.title.x = element_text(size = 12,face = "bold"), axis.title.y = element_text(size = 12,face = "bold"), axis.text.x = element_text(size = 8, face = "bold",angle=90) , panel.border = element_rect( color = "black", # 边框颜色 size = 1., # 边框粗细 linetype = "solid", # 线型(solid/dashed/dotted) fill = NA # 填充色(NA为透明) ), legend.position = "right") plot浓度1批次 plot浓度1by省市编号 <- ggplot(df20)+geom_point(aes(testDay, 浓度1,color=as.character(省市编号)))+ geom_line(aes(testDay,浓度1移动均值),color="blue")+ geom_line(aes(testDay,浓度1累计均值),color="green",linewidth=1.)+ geom_line(aes(testDay,浓度1允许波动范围),color="red",linewidth=1.)+ xlim(xmin, xmax) + ylim(0, ymax)+theme(legend.position ="right")+ labs( title = "浓度", # 主标题 x = "测试日期", # X轴标签 y = "浓度1", # Y轴标签 color = "" # 图例标题 )+ scale_x_date( date_labels = "%Y-%m-%d", # 格式符组合 date_breaks = "1 month" # 标签间隔(如 "2 weeks") )+ theme_minimal() + theme( plot.title = element_text(size = 14, face = "bold", hjust = 0.5), axis.title.x = element_text(size = 10,face = "bold"), axis.title.y = element_text(size = 10,face = "bold"), axis.text.x = element_text(size = 8, face = "bold",angle=90), legend.position = "right") plot浓度1by省市编号 plot浓度1省市编号<-ggplot(df20Top4区域)+geom_point(aes(testDay, 浓度1),color="orange")+ geom_line(aes(testDay,浓度1移动均值),color="blue")+ geom_line(aes(testDay,浓度1累计均值),color="green",linewidth=1.)+ geom_line(aes(testDay,浓度1允许波动范围),color="red",linewidth=1.)+ facet_wrap( ~ 省市编号,ncol=2) + labs( title = "浓度与地域关系", # 主标题 x = "测试日期", # X轴标签 y = "浓度1" )+ scale_fill_manual(values = c("red", "green")) + # 自定义颜色 theme_minimal() + theme( plot.title = element_text(size = 14, face = "bold", hjust = 0.5), axis.title.x = element_text(size = 12,face = "bold"), axis.title.y = element_text(size = 12,face = "bold"), axis.text.x = element_text(size = 8, face = "bold",angle=90) , panel.border = element_rect( color = "black", # 边框颜色 size = 1., # 边框粗细 linetype = "solid", # 线型(solid/dashed/dotted) fill = NA # 填充色(NA为透明) ), legend.position = "right") plot浓度1省市编号 ymax<-max(6,quantile(df20$浓度1,probs = 0.95, # 要计算的百分位(0-1之间) na.rm = TRUE)) plot浓度1by仪器 <- ggplot(df20)+geom_point(aes(testDay, 浓度1,color=as.character(仪器序列号)))+ geom_line(aes(testDay,浓度1移动均值),color="blue")+ geom_line(aes(testDay,浓度1累计均值),color="green",linewidth=1.)+ geom_line(aes(testDay,浓度1允许波动范围),color="red",linewidth=1.)+ xlim(xmin, xmax) + ylim(0, ymax)+theme(legend.position ="right")+ labs( title = "浓度", # 主标题 x = "测试日期", # X轴标签 y = "浓度1", # Y轴标签 color = "仪器序列号" # 图例标题 )+ scale_x_date( date_labels = "%Y-%m-%d", # 格式符组合 date_breaks = "1 month" # 标签间隔(如 "2 weeks") )+ theme_minimal() + theme( plot.title = element_text(size = 14, face = "bold", hjust = 0.5), axis.title.x = element_text(size = 10,face = "bold"), axis.title.y = element_text(size = 10,face = "bold"), axis.text.x = element_text(size = 8, face = "bold",angle=90), legend.position = "right") plot浓度1by仪器 plot浓度1仪器<-ggplot(df20Top4仪器)+geom_point(aes(testDay, 浓度1),color="orange")+ geom_line(aes(testDay,浓度1移动均值),color="blue")+ geom_line(aes(testDay,浓度1累计均值),color="green",linewidth=1.)+ geom_line(aes(testDay,浓度1允许波动范围),color="red",linewidth=1.)+ facet_wrap( ~ 仪器序列号,ncol=2) + labs( title = "浓度与仪器关系", # 主标题 x = "测试日期", # X轴标签 y = "浓度1" )+ scale_fill_manual(values = c("red", "green")) + # 自定义颜色 theme_minimal() + theme( plot.title = element_text(size = 14, face = "bold", hjust = 0.5), axis.title.x = element_text(size = 12,face = "bold"), axis.title.y = element_text(size = 12,face = "bold"), axis.text.x = element_text(size = 8, face = "bold",angle=90) , panel.border = element_rect( color = "black", # 边框颜色 size = 1., # 边框粗细 linetype = "solid", # 线型(solid/dashed/dotted) fill = NA # 填充色(NA为透明) ), legend.position = "right") plot浓度1仪器 ymax<-max(6,quantile(df20$C值,probs = 0.98, # 要计算的百分位(0-1之间) na.rm = TRUE)) plotC值by批次 <- ggplot(df20)+geom_point(aes(testDay, C值,color=as.character(批次名称)))+ geom_line(aes(testDay,C值移动均值),color="blue")+ geom_line(aes(testDay,C值累计均值),color="green",linewidth=1.)+ geom_line(aes(testDay,C值允许波动范围),color="red",linewidth=1.)+ xlim(xmin, xmax) + ylim(0, ymax)+theme(legend.position ="right")+ scale_y_log10()+ labs( title = "C值", # 主标题 x = "测试日期", # X轴标签 y = "C值", # Y轴标签 color = "批次名称" # 图例标题 )+ scale_x_date( date_labels = "%Y-%m-%d", # 格式符组合 date_breaks = "1 month" # 标签间隔(如 "2 weeks") )+ theme_minimal() + theme( plot.title = element_text(size = 14, face = "bold", hjust = 0.5), axis.title.x = element_text(size = 10,face = "bold"), axis.title.y = element_text(size = 10,face = "bold"), axis.text.x = element_text(size = 8, face = "bold",angle=90), legend.position = "right") plotC值by批次 plotC值批次<-ggplot(df20Top4批次)+geom_point(aes(testDay, C值),color="orange")+ geom_line(aes(testDay,C值移动均值),color="blue")+ geom_line(aes(testDay,C值累计均值),color="green",linewidth=1.)+ geom_line(aes(testDay,C值允许波动范围),color="red",linewidth=1.)+ scale_y_log10()+ facet_wrap( ~ 批次名称,ncol=2) + labs( title = "C值与试剂批次关系", # 主标题 x = "测试日期", # X轴标签 y = "C值" )+ scale_fill_manual(values = c("red", "green")) + # 自定义颜色 theme_minimal() + theme( plot.title = element_text(size = 14, face = "bold", hjust = 0.5), axis.title.x = element_text(size = 12,face = "bold"), axis.title.y = element_text(size = 12,face = "bold"), axis.text.x = element_text(size = 8, face = "bold",angle=90) , panel.border = element_rect( color = "black", # 边框颜色 size = 1., # 边框粗细 linetype = "solid", # 线型(solid/dashed/dotted) fill = NA # 填充色(NA为透明) ), legend.position = "right") plotC值批次 plotC值by省市编号 <- ggplot(df20)+geom_point(aes(testDay, C值,color=as.character(省市编号)))+ geom_line(aes(testDay,C值移动均值),color="blue")+ geom_line(aes(testDay,C值累计均值),color="green",linewidth=1.)+ geom_line(aes(testDay,C值允许波动范围),color="red",linewidth=1.)+ xlim(xmin, xmax) + ylim(0, ymax)+theme(legend.position ="right")+ labs( title = "C值", # 主标题 x = "测试日期", # X轴标签 y = "C值", # Y轴标签 color = "" # 图例标题 )+ scale_x_date( date_labels = "%Y-%m-%d", # 格式符组合 date_breaks = "1 month" # 标签间隔(如 "2 weeks") )+ scale_y_log10()+ theme_minimal() + theme( plot.title = element_text(size = 14, face = "bold", hjust = 0.5), axis.title.x = element_text(size = 10,face = "bold"), axis.title.y = element_text(size = 10,face = "bold"), axis.text.x = element_text(size = 8, face = "bold",angle=90), legend.position = "right") plotC值by省市编号 plotC值省市编号<-ggplot(df20Top4区域)+geom_point(aes(testDay, C值),color="orange")+ geom_line(aes(testDay,C值移动均值),color="blue")+ geom_line(aes(testDay,C值累计均值),color="green",linewidth=1.)+ geom_line(aes(testDay,C值允许波动范围),color="red",linewidth=1.)+ facet_wrap( ~ 省市编号,ncol=2) + labs( title = "C值与地域关系", # 主标题 x = "测试日期", # X轴标签 y = "C值" )+ scale_fill_manual(values = c("red", "green")) + # 自定义颜色 scale_y_log10()+ theme_minimal() + theme( plot.title = element_text(size = 14, face = "bold", hjust = 0.5), axis.title.x = element_text(size = 12,face = "bold"), axis.title.y = element_text(size = 12,face = "bold"), axis.text.x = element_text(size = 8, face = "bold",angle=90) , panel.border = element_rect( color = "black", # 边框颜色 size = 1., # 边框粗细 linetype = "solid", # 线型(solid/dashed/dotted) fill = NA # 填充色(NA为透明) ), legend.position = "right") plotC值省市编号 plotC值by仪器 <- ggplot(df20)+geom_point(aes(testDay, C值,color=as.character(仪器序列号)))+ geom_line(aes(testDay,C值移动均值),color="blue")+ geom_line(aes(testDay,C值累计均值),color="green",linewidth=1.)+ geom_line(aes(testDay,C值允许波动范围),color="red",linewidth=1.)+ xlim(xmin, xmax) + ylim(0, ymax)+theme(legend.position ="right")+ labs( title = "C值", # 主标题 x = "测试日期", # X轴标签 y = "C值", # Y轴标签 color = "仪器序列号" # 图例标题 )+ scale_x_date( date_labels = "%Y-%m-%d", # 格式符组合 date_breaks = "1 month" # 标签间隔(如 "2 weeks") )+ scale_y_log10()+ theme_minimal() + theme( plot.title = element_text(size = 14, face = "bold", hjust = 0.5), axis.title.x = element_text(size = 10,face = "bold"), axis.title.y = element_text(size = 10,face = "bold"), axis.text.x = element_text(size = 8, face = "bold",angle=90), legend.position = "right") plotC值by仪器 plotC值仪器<-ggplot(df20Top4仪器)+geom_point(aes(testDay, C值),color="orange")+ geom_line(aes(testDay,C值移动均值),color="blue")+ geom_line(aes(testDay,C值累计均值),color="green",linewidth=1.)+ geom_line(aes(testDay,C值允许波动范围),color="red",linewidth=1.)+ facet_wrap( ~ 仪器序列号,ncol=2) + labs( title = "C值与仪器关系", # 主标题 x = "测试日期", # X轴标签 y = "C值" )+ scale_fill_manual(values = c("red", "green")) + # 自定义颜色 scale_y_log10()+ theme_minimal() + theme( plot.title = element_text(size = 14, face = "bold", hjust = 0.5), axis.title.x = element_text(size = 12,face = "bold"), axis.title.y = element_text(size = 12,face = "bold"), axis.text.x = element_text(size = 8, face = "bold",angle=90) , panel.border = element_rect( color = "black", # 边框颜色 size = 1., # 边框粗细 linetype = "solid", # 线型(solid/dashed/dotted) fill = NA # 填充色(NA为透明) ), legend.position = "right") plotC值仪器 ymax<-max(6,quantile(df20$T值,probs = 0.98, # 要计算的百分位(0-1之间) na.rm = TRUE)) plotT值by批次 <- ggplot(df20)+geom_point(aes(testDay, T值,color=as.character(批次名称)))+ geom_line(aes(testDay,T值移动均值),color="blue")+ geom_line(aes(testDay,T值累计均值),color="green",linewidth=1.)+ geom_line(aes(testDay,T值允许波动范围),color="red",linewidth=1.)+ xlim(xmin, xmax) + ylim(0, ymax)+theme(legend.position ="right")+ labs( title = "T值", # 主标题 x = "测试日期", # X轴标签 y = "T值", # Y轴标签 color = "批次名称" # 图例标题 )+ scale_x_date( date_labels = "%Y-%m-%d", # 格式符组合 date_breaks = "1 month" # 标签间隔(如 "2 weeks") )+ scale_y_log10()+ theme_minimal() + theme( plot.title = element_text(size = 14, face = "bold", hjust = 0.5), axis.title.x = element_text(size = 10,face = "bold"), axis.title.y = element_text(size = 10,face = "bold"), axis.text.x = element_text(size = 8, face = "bold",angle=90), legend.position = "right") plotT值by批次 plotT值批次<-ggplot(df20Top4批次)+geom_point(aes(testDay, T值),color="orange")+ geom_line(aes(testDay,T值移动均值),color="blue")+ geom_line(aes(testDay,T值累计均值),color="green",linewidth=1.)+ geom_line(aes(testDay,T值允许波动范围),color="red",linewidth=1.)+ facet_wrap( ~ 批次名称,ncol=2) + labs( title = "T值与试剂批次关系", # 主标题 x = "测试日期", # X轴标签 y = "T值" )+ scale_fill_manual(values = c("red", "green")) + # 自定义颜色 scale_y_log10()+ theme_minimal() + theme( plot.title = element_text(size = 14, face = "bold", hjust = 0.5), axis.title.x = element_text(size = 12,face = "bold"), axis.title.y = element_text(size = 12,face = "bold"), axis.text.x = element_text(size = 8, face = "bold",angle=90) , panel.border = element_rect( color = "black", # 边框颜色 size = 1., # 边框粗细 linetype = "solid", # 线型(solid/dashed/dotted) fill = NA # 填充色(NA为透明) ), legend.position = "right") plotT值批次 plotT值by省市编号 <- ggplot(df20)+geom_point(aes(testDay, T值,color=as.character(省市编号)))+ geom_line(aes(testDay,T值移动均值),color="blue")+ geom_line(aes(testDay,T值累计均值),color="green",linewidth=1.)+ geom_line(aes(testDay,T值允许波动范围),color="red",linewidth=1.)+ xlim(xmin, xmax) + ylim(0, ymax)+theme(legend.position ="right")+ labs( title = "T值", # 主标题 x = "测试日期", # X轴标签 y = "T值", # Y轴标签 color = "" # 图例标题 )+ scale_x_date( date_labels = "%Y-%m-%d", # 格式符组合 date_breaks = "1 month" # 标签间隔(如 "2 weeks") )+ scale_y_log10()+ theme_minimal() + theme( plot.title = element_text(size = 14, face = "bold", hjust = 0.5), axis.title.x = element_text(size = 10,face = "bold"), axis.title.y = element_text(size = 10,face = "bold"), axis.text.x = element_text(size = 8, face = "bold",angle=90), legend.position = "right") plotT值by省市编号 plotT值省市编号<-ggplot(df20Top4区域)+geom_point(aes(testDay, T值),color="orange")+ geom_line(aes(testDay,T值移动均值),color="blue")+ geom_line(aes(testDay,T值累计均值),color="green",linewidth=1.)+ geom_line(aes(testDay,T值允许波动范围),color="red",linewidth=1.)+ facet_wrap( ~ 省市编号,ncol=2) + labs( title = "T值与地域关系", # 主标题 x = "测试日期", # X轴标签 y = "T值" )+ scale_fill_manual(values = c("red", "green")) + # 自定义颜色 scale_y_log10()+ theme_minimal() + theme( plot.title = element_text(size = 14, face = "bold", hjust = 0.5), axis.title.x = element_text(size = 12,face = "bold"), axis.title.y = element_text(size = 12,face = "bold"), axis.text.x = element_text(size = 8, face = "bold",angle=90) , panel.border = element_rect( color = "black", # 边框颜色 size = 1., # 边框粗细 linetype = "solid", # 线型(solid/dashed/dotted) fill = NA # 填充色(NA为透明) ), legend.position = "right") plotT值省市编号 plotT值by仪器 <- ggplot(df20)+geom_point(aes(testDay, T值,color=as.character(仪器序列号)))+ geom_line(aes(testDay,T值移动均值),color="blue")+ geom_line(aes(testDay,T值累计均值),color="green",linewidth=1.)+ geom_line(aes(testDay,T值允许波动范围),color="red",linewidth=1.)+ xlim(xmin, xmax) + ylim(0, ymax)+theme(legend.position ="right")+ labs( title = "T值", # 主标题 x = "测试日期", # X轴标签 y = "T值", # Y轴标签 color = "仪器序列号" # 图例标题 )+ scale_x_date( date_labels = "%Y-%m-%d", # 格式符组合 date_breaks = "1 month" # 标签间隔(如 "2 weeks") )+ scale_y_log10()+ theme_minimal() + theme( plot.title = element_text(size = 14, face = "bold", hjust = 0.5), axis.title.x = element_text(size = 10,face = "bold"), axis.title.y = element_text(size = 10,face = "bold"), axis.text.x = element_text(size = 8, face = "bold",angle=90), legend.position = "right") plotT值by仪器 plotT值仪器<-ggplot(df20Top4仪器)+geom_point(aes(testDay, T值),color="orange")+ geom_line(aes(testDay,T值移动均值),color="blue")+ geom_line(aes(testDay,T值累计均值),color="green",linewidth=1.)+ geom_line(aes(testDay,T值允许波动范围),color="red",linewidth=1.)+ facet_wrap( ~ 仪器序列号,ncol=2) + labs( title = "T值与仪器关系", # 主标题 x = "测试日期", # X轴标签 y = "T值" )+ scale_fill_manual(values = c("red", "green")) + # 自定义颜色 scale_y_log10()+ theme_minimal() + theme( plot.title = element_text(size = 14, face = "bold", hjust = 0.5), axis.title.x = element_text(size = 12,face = "bold"), axis.title.y = element_text(size = 12,face = "bold"), axis.text.x = element_text(size = 8, face = "bold",angle=90) , panel.border = element_rect( color = "black", # 边框颜色 size = 1., # 边框粗细 linetype = "solid", # 线型(solid/dashed/dotted) fill = NA # 填充色(NA为透明) ), legend.position = "right") plotT值仪器 ymax<-max(6,quantile(df20$ToverC值,probs = 0.98, # 要计算的百分位(0-1之间) na.rm = TRUE)) plotToverC值by批次 <- ggplot(df20)+geom_point(aes(testDay, ToverC值,color=as.character(批次名称)))+ geom_line(aes(testDay,ToverC值移动均值),color="blue")+ geom_line(aes(testDay,ToverC值累计均值),color="green",linewidth=1.)+ geom_line(aes(testDay,ToverC值允许波动范围),color="red",linewidth=1.)+ xlim(xmin, xmax) + ylim(0, ymax)+theme(legend.position ="right")+ labs( title = "T/C值", # 主标题 x = "测试日期", # X轴标签 y = "T/C值", # Y轴标签 color = "批次名称" # 图例标题 )+ scale_x_date( date_labels = "%Y-%m-%d", # 格式符组合 date_breaks = "1 month" # 标签间隔(如 "2 weeks") )+ theme_minimal() + theme( plot.title = element_text(size = 14, face = "bold", hjust = 0.5), axis.title.x = element_text(size = 10,face = "bold"), axis.title.y = element_text(size = 10,face = "bold"), axis.text.x = element_text(size = 8, face = "bold",angle=90), legend.position = "right") plotToverC值by批次 plotToverC值批次<-ggplot(df20Top4批次)+geom_point(aes(testDay, ToverC值),color="orange")+ geom_line(aes(testDay,ToverC值移动均值),color="blue")+ geom_line(aes(testDay,ToverC值累计均值),color="green",linewidth=1.)+ geom_line(aes(testDay,ToverC值允许波动范围),color="red",linewidth=1.)+ facet_wrap( ~ 批次名称,ncol=2) + labs( title = "T/C值与试剂批次关系", # 主标题 x = "测试日期", # X轴标签 y = "T/C值" )+ scale_fill_manual(values = c("red", "green")) + # 自定义颜色 theme_minimal() + theme( plot.title = element_text(size = 14, face = "bold", hjust = 0.5), axis.title.x = element_text(size = 12,face = "bold"), axis.title.y = element_text(size = 12,face = "bold"), axis.text.x = element_text(size = 8, face = "bold",angle=90) , panel.border = element_rect( color = "black", # 边框颜色 size = 1., # 边框粗细 linetype = "solid", # 线型(solid/dashed/dotted) fill = NA # 填充色(NA为透明) ), legend.position = "right") plotToverC值批次 plotToverC值by省市编号 <- ggplot(df20)+geom_point(aes(testDay, ToverC值,color=as.character(省市编号)))+ geom_line(aes(testDay,ToverC值移动均值),color="blue")+ geom_line(aes(testDay,ToverC值累计均值),color="green",linewidth=1.)+ geom_line(aes(testDay,ToverC值允许波动范围),color="red",linewidth=1.)+ xlim(xmin, xmax) + ylim(0, ymax)+theme(legend.position ="right")+ labs( title = "T/C值", # 主标题 x = "测试日期", # X轴标签 y = "T/C值", # Y轴标签 color = "" # 图例标题 )+ scale_x_date( date_labels = "%Y-%m-%d", # 格式符组合 date_breaks = "1 month" # 标签间隔(如 "2 weeks") )+ theme_minimal() + theme( plot.title = element_text(size = 14, face = "bold", hjust = 0.5), axis.title.x = element_text(size = 10,face = "bold"), axis.title.y = element_text(size = 10,face = "bold"), axis.text.x = element_text(size = 8, face = "bold",angle=90), legend.position = "right") plotToverC值by省市编号 plotToverC值省市编号<-ggplot(df20Top4区域)+geom_point(aes(testDay, ToverC值),color="orange")+ geom_line(aes(testDay,ToverC值移动均值),color="blue")+ geom_line(aes(testDay,ToverC值累计均值),color="green",linewidth=1.)+ geom_line(aes(testDay,ToverC值允许波动范围),color="red",linewidth=1.)+ facet_wrap( ~ 省市编号,ncol=2) + labs( title = "T/C值与地域关系", # 主标题 x = "测试日期", # X轴标签 y = "T/C值" )+ scale_fill_manual(values = c("red", "green")) + # 自定义颜色 theme_minimal() + theme( plot.title = element_text(size = 14, face = "bold", hjust = 0.5), axis.title.x = element_text(size = 12,face = "bold"), axis.title.y = element_text(size = 12,face = "bold"), axis.text.x = element_text(size = 8, face = "bold",angle=90) , panel.border = element_rect( color = "black", # 边框颜色 size = 1., # 边框粗细 linetype = "solid", # 线型(solid/dashed/dotted) fill = NA # 填充色(NA为透明) ), legend.position = "right") plotToverC值省市编号 plotToverC值by仪器 <- ggplot(df20)+geom_point(aes(testDay, ToverC值,color=as.character(仪器序列号)))+ geom_line(aes(testDay,ToverC值移动均值),color="blue")+ geom_line(aes(testDay,ToverC值累计均值),color="green",linewidth=1.)+ geom_line(aes(testDay,ToverC值允许波动范围),color="red",linewidth=1.)+ xlim(xmin, xmax) + ylim(0, ymax)+theme(legend.position ="right")+ labs( title = "T/C值", # 主标题 x = "测试日期", # X轴标签 y = "T/C值", # Y轴标签 color = "仪器序列号" # 图例标题 )+ scale_x_date( date_labels = "%Y-%m-%d", # 格式符组合 date_breaks = "1 month" # 标签间隔(如 "2 weeks") )+ theme_minimal() + theme( plot.title = element_text(size = 14, face = "bold", hjust = 0.5), axis.title.x = element_text(size = 10,face = "bold"), axis.title.y = element_text(size = 10,face = "bold"), axis.text.x = element_text(size = 8, face = "bold",angle=90), legend.position = "right") plotToverC值by仪器 plotToverC值仪器<-ggplot(df20Top4仪器)+geom_point(aes(testDay, ToverC值),color="orange")+ geom_line(aes(testDay,ToverC值移动均值),color="blue")+ geom_line(aes(testDay,ToverC值累计均值),color="green",linewidth=1.)+ geom_line(aes(testDay,ToverC值允许波动范围),color="red",linewidth=1.)+ facet_wrap( ~ 仪器序列号,ncol=2) + labs( title = "T/C值与仪器关系", # 主标题 x = "测试日期", # X轴标签 y = "T/C值" )+ scale_fill_manual(values = c("red", "green")) + # 自定义颜色 theme_minimal() + theme( plot.title = element_text(size = 14, face = "bold", hjust = 0.5), axis.title.x = element_text(size = 12,face = "bold"), axis.title.y = element_text(size = 12,face = "bold"), axis.text.x = element_text(size = 8, face = "bold",angle=90) , panel.border = element_rect( color = "black", # 边框颜色 size = 1., # 边框粗细 linetype = "solid", # 线型(solid/dashed/dotted) fill = NA # 填充色(NA为透明) ), legend.position = "right") plotToverC值仪器 ymax<-1.0 plot结论by批次 <- ggplot(df20)+geom_point(aes(testDay, 是否阳性,color=as.character(批次名称)))+ geom_line(aes(testDay,结论移动均值),color="blue")+ geom_line(aes(testDay,结论累计均值),color="green",linewidth=1.)+ geom_line(aes(testDay,结论允许波动范围),color="red",linewidth=1.)+ xlim(xmin, xmax) + ylim(0, ymax)+theme(legend.position ="right")+ labs( title = "结论/阳性率", # 主标题 x = "测试日期", # X轴标签 y = "结论/阳性率", # Y轴标签 color = "批次名称" # 图例标题 )+ scale_x_date( date_labels = "%Y-%m-%d", # 格式符组合 date_breaks = "1 month" # 标签间隔(如 "2 weeks") )+ theme_minimal() + theme( plot.title = element_text(size = 14, face = "bold", hjust = 0.5), axis.title.x = element_text(size = 10,face = "bold"), axis.title.y = element_text(size = 10,face = "bold"), axis.text.x = element_text(size = 8, face = "bold",angle=90), legend.position = "right") plot结论by批次 plot结论批次<-ggplot(df20Top4批次)+geom_point(aes(testDay, 是否阳性),color="orange")+ geom_line(aes(testDay,结论移动均值),color="blue")+ geom_line(aes(testDay,结论累计均值),color="green",linewidth=1.)+ geom_line(aes(testDay,结论允许波动范围),color="red",linewidth=1.)+ facet_wrap( ~ 批次名称,ncol=2) + labs( title = "结论/阳性率与试剂批次关系", # 主标题 x = "测试日期", # X轴标签 y = "结论/阳性率" )+ scale_fill_manual(values = c("red", "green")) + # 自定义颜色 theme_minimal() + theme( plot.title = element_text(size = 14, face = "bold", hjust = 0.5), axis.title.x = element_text(size = 12,face = "bold"), axis.title.y = element_text(size = 12,face = "bold"), axis.text.x = element_text(size = 8, face = "bold",angle=90) , panel.border = element_rect( color = "black", # 边框颜色 size = 1., # 边框粗细 linetype = "solid", # 线型(solid/dashed/dotted) fill = NA # 填充色(NA为透明) ), legend.position = "right") plot结论批次 plot结论by省市编号 <- ggplot(df20)+geom_point(aes(testDay, 是否阳性,color=as.character(省市编号)))+ geom_line(aes(testDay,结论移动均值),color="blue")+ geom_line(aes(testDay,结论累计均值),color="green",linewidth=1.)+ geom_line(aes(testDay,结论允许波动范围),color="red",linewidth=1.)+ xlim(xmin, xmax) + ylim(0, ymax)+theme(legend.position ="right")+ labs( title = "结论/阳性率", # 主标题 x = "测试日期", # X轴标签 y = "结论/阳性率", # Y轴标签 color = "" # 图例标题 )+ scale_x_date( date_labels = "%Y-%m-%d", # 格式符组合 date_breaks = "1 month" # 标签间隔(如 "2 weeks") )+ theme_minimal() + theme( plot.title = element_text(size = 14, face = "bold", hjust = 0.5), axis.title.x = element_text(size = 10,face = "bold"), axis.title.y = element_text(size = 10,face = "bold"), axis.text.x = element_text(size = 8, face = "bold",angle=90), legend.position = "right") plot结论by省市编号 plot结论省市编号<-ggplot(df20Top4区域)+geom_point(aes(testDay, 是否阳性),color="orange")+ geom_line(aes(testDay,结论移动均值),color="blue")+ geom_line(aes(testDay,结论累计均值),color="green",linewidth=1.)+ geom_line(aes(testDay,结论允许波动范围),color="red",linewidth=1.)+ facet_wrap( ~ 省市编号,ncol=2) + labs( title = "结论/阳性率与地域关系", # 主标题 x = "测试日期", # X轴标签 y = "结论/阳性率" )+ scale_fill_manual(values = c("red", "green")) + # 自定义颜色 theme_minimal() + theme( plot.title = element_text(size = 14, face = "bold", hjust = 0.5), axis.title.x = element_text(size = 12,face = "bold"), axis.title.y = element_text(size = 12,face = "bold"), axis.text.x = element_text(size = 8, face = "bold",angle=90) , panel.border = element_rect( color = "black", # 边框颜色 size = 1., # 边框粗细 linetype = "solid", # 线型(solid/dashed/dotted) fill = NA # 填充色(NA为透明) ), legend.position = "right") plot结论省市编号 plot结论by仪器 <- ggplot(df20)+geom_point(aes(testDay, 是否阳性,color=as.character(仪器序列号)))+ geom_line(aes(testDay,结论移动均值),color="blue")+ geom_line(aes(testDay,结论累计均值),color="green",linewidth=1.)+ geom_line(aes(testDay,结论允许波动范围),color="red",linewidth=1.)+ xlim(xmin, xmax) + ylim(0, ymax)+theme(legend.position ="right")+ labs( title = "结论/阳性率", # 主标题 x = "测试日期", # X轴标签 y = "结论/阳性率", # Y轴标签 color = "仪器序列号" # 图例标题 )+ scale_x_date( date_labels = "%Y-%m-%d", # 格式符组合 date_breaks = "1 month" # 标签间隔(如 "2 weeks") )+ theme_minimal() + theme( plot.title = element_text(size = 14, face = "bold", hjust = 0.5), axis.title.x = element_text(size = 10,face = "bold"), axis.title.y = element_text(size = 10,face = "bold"), axis.text.x = element_text(size = 8, face = "bold",angle=90), legend.position = "right") plot结论by仪器 plot结论仪器<-ggplot(df20Top4仪器)+geom_point(aes(testDay, 是否阳性),color="orange")+ geom_line(aes(testDay,结论移动均值),color="blue")+ geom_line(aes(testDay,结论累计均值),color="green",linewidth=1.)+ geom_line(aes(testDay,结论允许波动范围),color="red",linewidth=1.)+ facet_wrap( ~ 仪器序列号,ncol=2) + labs( title = "结论/阳性率与仪器关系", # 主标题 x = "测试日期", # X轴标签 y = "结论/阳性率" )+ scale_fill_manual(values = c("red", "green")) + # 自定义颜色 theme_minimal() + theme( plot.title = element_text(size = 14, face = "bold", hjust = 0.5), axis.title.x = element_text(size = 12,face = "bold"), axis.title.y = element_text(size = 12,face = "bold"), axis.text.x = element_text(size = 8, face = "bold",angle=90) , panel.border = element_rect( color = "black", # 边框颜色 size = 1., # 边框粗细 linetype = "solid", # 线型(solid/dashed/dotted) fill = NA # 填充色(NA为透明) ), legend.position = "right") plot结论仪器 df20$结论Outlier<-1 df20$结论Outlier[df20$结论允许波动范围-df20$结论移动均值>0 & df20$结论移动均值-(df20$结论累计均值-2*df20$结论累计标差)>0]<-0 df20$结论Outlier[is.na(df20$结论累计标差)]<-NA summary(df20$结论Outlier) dfBy批次Outlier <- df20 %>% group_by(批次名称) %>% summarise( outlierCount=sum(结论Outlier,na.rm=TRUE)) dfBy批次Outliertop4<-dfBy批次Outlier$批次名称[order(-dfBy批次Outlier$outlierCount)][1:4] dfBy批次Outliertop4<-dfBy批次Outliertop4[!is.na(dfBy批次Outliertop4)] df20Top4批次Outlier<-df20[df20$批次名称 %in% dfBy批次Outliertop4,] df20Top4批次Outlier$批次名称<-factor(df20Top4批次Outlier$批次名称,levels = dfBy批次Outliertop4) plot浓度1批次Outlier<-ggplot(df20Top4批次Outlier)+geom_point(aes(testDay, 浓度1),color="orange")+ geom_line(aes(testDay,浓度1移动均值),color="blue")+ geom_line(aes(testDay,浓度1累计均值),color="green",linewidth=1.)+ geom_line(aes(testDay,浓度1允许波动范围),color="red",linewidth=1.)+ facet_wrap( ~ 批次名称,ncol=2) + labs( title = "浓度与试剂批次关系", # 主标题 x = "测试日期", # X轴标签 y = "浓度1" )+ scale_fill_manual(values = c("red", "green")) + # 自定义颜色 theme_minimal() + theme( plot.title = element_text(size = 14, face = "bold", hjust = 0.5), axis.title.x = element_text(size = 12,face = "bold"), axis.title.y = element_text(size = 12,face = "bold"), axis.text.x = element_text(size = 8, face = "bold",angle=90) , panel.border = element_rect( color = "black", # 边框颜色 size = 1., # 边框粗细 linetype = "solid", # 线型(solid/dashed/dotted) fill = NA # 填充色(NA为透明) ), legend.position = "right") plot浓度1批次Outlier plotC值批次Outlier<-ggplot(df20Top4批次Outlier)+geom_point(aes(testDay, C值),color="orange")+ geom_line(aes(testDay,C值移动均值),color="blue")+ geom_line(aes(testDay,C值累计均值),color="green",linewidth=1.)+ geom_line(aes(testDay,C值允许波动范围),color="red",linewidth=1.)+ facet_wrap( ~ 批次名称,ncol=2) + labs( title = "C值与试剂批次关系", # 主标题 x = "测试日期", # X轴标签 y = "C值" )+ scale_fill_manual(values = c("red", "green")) + # 自定义颜色 scale_y_log10()+ theme_minimal() + theme( plot.title = element_text(size = 14, face = "bold", hjust = 0.5), axis.title.x = element_text(size = 12,face = "bold"), axis.title.y = element_text(size = 12,face = "bold"), axis.text.x = element_text(size = 8, face = "bold",angle=90) , panel.border = element_rect( color = "black", # 边框颜色 size = 1., # 边框粗细 linetype = "solid", # 线型(solid/dashed/dotted) fill = NA # 填充色(NA为透明) ), legend.position = "right") plotC值批次Outlier plotT值批次Outlier<-ggplot(df20Top4批次Outlier)+geom_point(aes(testDay, T值),color="orange")+ geom_line(aes(testDay,T值移动均值),color="blue")+ geom_line(aes(testDay,T值累计均值),color="green",linewidth=1.)+ geom_line(aes(testDay,T值允许波动范围),color="red",linewidth=1.)+ facet_wrap( ~ 批次名称,ncol=2) + labs( title = "T值与试剂批次关系", # 主标题 x = "测试日期", # X轴标签 y = "T值" )+ scale_fill_manual(values = c("red", "green")) + # 自定义颜色 scale_y_log10()+ theme_minimal() + theme( plot.title = element_text(size = 14, face = "bold", hjust = 0.5), axis.title.x = element_text(size = 12,face = "bold"), axis.title.y = element_text(size = 12,face = "bold"), axis.text.x = element_text(size = 8, face = "bold",angle=90) , panel.border = element_rect( color = "black", # 边框颜色 size = 1., # 边框粗细 linetype = "solid", # 线型(solid/dashed/dotted) fill = NA # 填充色(NA为透明) ), legend.position = "right") plotT值批次Outlier plotToverC值批次Outlier<-ggplot(df20Top4批次Outlier)+geom_point(aes(testDay, ToverC值),color="orange")+ geom_line(aes(testDay,ToverC值移动均值),color="blue")+ geom_line(aes(testDay,ToverC值累计均值),color="green",linewidth=1.)+ geom_line(aes(testDay,ToverC值允许波动范围),color="red",linewidth=1.)+ facet_wrap( ~ 批次名称,ncol=2) + labs( title = "T/C值与试剂批次关系", # 主标题 x = "测试日期", # X轴标签 y = "T/C值" )+ scale_fill_manual(values = c("red", "green")) + # 自定义颜色 theme_minimal() + theme( plot.title = element_text(size = 14, face = "bold", hjust = 0.5), axis.title.x = element_text(size = 12,face = "bold"), axis.title.y = element_text(size = 12,face = "bold"), axis.text.x = element_text(size = 8, face = "bold",angle=90) , panel.border = element_rect( color = "black", # 边框颜色 size = 1., # 边框粗细 linetype = "solid", # 线型(solid/dashed/dotted) fill = NA # 填充色(NA为透明) ), legend.position = "right") plotToverC值批次Outlier plot结论批次Outlier<-ggplot(df20Top4批次Outlier)+geom_point(aes(testDay, 是否阳性),color="orange")+ geom_line(aes(testDay,结论移动均值),color="blue")+ geom_line(aes(testDay,结论累计均值),color="green",linewidth=1.)+ geom_line(aes(testDay,结论允许波动范围),color="red",linewidth=1.)+ facet_wrap( ~ 批次名称,ncol=2) + labs( title = "结论/阳性率与试剂批次关系", # 主标题 x = "测试日期", # X轴标签 y = "结论/阳性率" )+ scale_fill_manual(values = c("red", "green")) + # 自定义颜色 theme_minimal() + theme( plot.title = element_text(size = 14, face = "bold", hjust = 0.5), axis.title.x = element_text(size = 12,face = "bold"), axis.title.y = element_text(size = 12,face = "bold"), axis.text.x = element_text(size = 8, face = "bold",angle=90) , panel.border = element_rect( color = "black", # 边框颜色 size = 1., # 边框粗细 linetype = "solid", # 线型(solid/dashed/dotted) fill = NA # 填充色(NA为透明) ), legend.position = "right") plot结论批次Outlier if(FALSE){ dfBy区域Outlier <- df20 %>% group_by(省市编号) %>% summarise( outlierCount=sum(结论Outlier,na.rm=TRUE)) dfBy区域Outliertop4<-dfBy区域Outlier$省市编号[order(-dfBy区域Outlier$outlierCount)][1:4] dfBy区域Outliertop4<-dfBy区域Outliertop4[!is.na(dfBy区域Outliertop4)] df20Top4区域Outlier<-df20[df20$省市编号 %in% dfBy区域Outliertop4,] df20Top4区域Outlier$省市编号<-factor(df20Top4区域Outlier$省市编号,levels = dfBy区域Outliertop4) plot浓度1区域Outlier<-ggplot(df20Top4区域Outlier)+geom_point(aes(testDay, 浓度1),color="orange")+ geom_line(aes(testDay,浓度1移动均值),color="blue")+ geom_line(aes(testDay,浓度1累计均值),color="green",linewidth=1.)+ geom_line(aes(testDay,浓度1允许波动范围),color="red",linewidth=1.)+ facet_wrap( ~ 省市编号,ncol=2) + labs( title = "浓度与地域关系", # 主标题 x = "测试日期", # X轴标签 y = "浓度1" )+ scale_fill_manual(values = c("red", "green")) + # 自定义颜色 theme_minimal() + theme( plot.title = element_text(size = 14, face = "bold", hjust = 0.5), axis.title.x = element_text(size = 12,face = "bold"), axis.title.y = element_text(size = 12,face = "bold"), axis.text.x = element_text(size = 8, face = "bold",angle=90) , panel.border = element_rect( color = "black", # 边框颜色 size = 1., # 边框粗细 linetype = "solid", # 线型(solid/dashed/dotted) fill = NA # 填充色(NA为透明) ), legend.position = "right") plot浓度1区域Outlier plotC值区域Outlier<-ggplot(df20Top4区域Outlier)+geom_point(aes(testDay, C值),color="orange")+ geom_line(aes(testDay,C值移动均值),color="blue")+ geom_line(aes(testDay,C值累计均值),color="green",linewidth=1.)+ geom_line(aes(testDay,C值允许波动范围),color="red",linewidth=1.)+ facet_wrap( ~ 省市编号,ncol=2) + labs( title = "C值与地域关系", # 主标题 x = "测试日期", # X轴标签 y = "C值" )+ scale_fill_manual(values = c("red", "green")) + # 自定义颜色 scale_y_log10()+ theme_minimal() + theme( plot.title = element_text(size = 14, face = "bold", hjust = 0.5), axis.title.x = element_text(size = 12,face = "bold"), axis.title.y = element_text(size = 12,face = "bold"), axis.text.x = element_text(size = 8, face = "bold",angle=90) , panel.border = element_rect( color = "black", # 边框颜色 size = 1., # 边框粗细 linetype = "solid", # 线型(solid/dashed/dotted) fill = NA # 填充色(NA为透明) ), legend.position = "right") plotC值区域Outlier plotT值区域Outlier<-ggplot(df20Top4区域Outlier)+geom_point(aes(testDay, T值),color="orange")+ geom_line(aes(testDay,T值移动均值),color="blue")+ geom_line(aes(testDay,T值累计均值),color="green",linewidth=1.)+ geom_line(aes(testDay,T值允许波动范围),color="red",linewidth=1.)+ facet_wrap( ~ 省市编号,ncol=2) + labs( title = "T值与地域关系", # 主标题 x = "测试日期", # X轴标签 y = "T值" )+ scale_fill_manual(values = c("red", "green")) + # 自定义颜色 scale_y_log10()+ theme_minimal() + theme( plot.title = element_text(size = 14, face = "bold", hjust = 0.5), axis.title.x = element_text(size = 12,face = "bold"), axis.title.y = element_text(size = 12,face = "bold"), axis.text.x = element_text(size = 8, face = "bold",angle=90) , panel.border = element_rect( color = "black", # 边框颜色 size = 1., # 边框粗细 linetype = "solid", # 线型(solid/dashed/dotted) fill = NA # 填充色(NA为透明) ), legend.position = "right") plotT值区域Outlier plotToverC值区域Outlier<-ggplot(df20Top4区域Outlier)+geom_point(aes(testDay, ToverC值),color="orange")+ geom_line(aes(testDay,ToverC值移动均值),color="blue")+ geom_line(aes(testDay,ToverC值累计均值),color="green",linewidth=1.)+ geom_line(aes(testDay,ToverC值允许波动范围),color="red",linewidth=1.)+ facet_wrap( ~ 省市编号,ncol=2) + labs( title = "T/C值与地域关系", # 主标题 x = "测试日期", # X轴标签 y = "T/C值" )+ scale_fill_manual(values = c("red", "green")) + # 自定义颜色 theme_minimal() + theme( plot.title = element_text(size = 14, face = "bold", hjust = 0.5), axis.title.x = element_text(size = 12,face = "bold"), axis.title.y = element_text(size = 12,face = "bold"), axis.text.x = element_text(size = 8, face = "bold",angle=90) , panel.border = element_rect( color = "black", # 边框颜色 size = 1., # 边框粗细 linetype = "solid", # 线型(solid/dashed/dotted) fill = NA # 填充色(NA为透明) ), legend.position = "right") plotToverC值区域Outlier plot结论区域Outlier<-ggplot(df20Top4区域Outlier)+geom_point(aes(testDay, 是否阳性),color="orange")+ geom_line(aes(testDay,结论移动均值),color="blue")+ geom_line(aes(testDay,结论累计均值),color="green",linewidth=1.)+ geom_line(aes(testDay,结论允许波动范围),color="red",linewidth=1.)+ facet_wrap( ~ 省市编号,ncol=2) + labs( title = "结论/阳性率与地域关系", # 主标题 x = "测试日期", # X轴标签 y = "结论/阳性率" )+ scale_fill_manual(values = c("red", "green")) + # 自定义颜色 theme_minimal() + theme( plot.title = element_text(size = 14, face = "bold", hjust = 0.5), axis.title.x = element_text(size = 12,face = "bold"), axis.title.y = element_text(size = 12,face = "bold"), axis.text.x = element_text(size = 8, face = "bold",angle=90) , panel.border = element_rect( color = "black", # 边框颜色 size = 1., # 边框粗细 linetype = "solid", # 线型(solid/dashed/dotted) fill = NA # 填充色(NA为透明) ), legend.position = "right") plot结论区域Outlier } if(FALSE){ dfBy仪器Outlier <- df20 %>% group_by(仪器序列号) %>% summarise( outlierCount=sum(结论Outlier,na.rm=TRUE)) dfBy仪器Outliertop4<-dfBy仪器Outlier$仪器序列号[order(-dfBy仪器Outlier$outlierCount)][1:4] dfBy仪器Outliertop4<-dfBy仪器Outliertop4[!is.na(dfBy仪器Outliertop4)] df20Top4仪器Outlier<-df20[df20$仪器序列号 %in% dfBy仪器Outliertop4,] df20Top4仪器Outlier$仪器序列号<-factor(df20Top4仪器Outlier$仪器序列号,levels = dfBy仪器Outliertop4) plot浓度1仪器Outlier<-ggplot(df20Top4仪器Outlier)+geom_point(aes(testDay, 浓度1),color="orange")+ geom_line(aes(testDay,浓度1移动均值),color="blue")+ geom_line(aes(testDay,浓度1累计均值),color="green",linewidth=1.)+ geom_line(aes(testDay,浓度1允许波动范围),color="red",linewidth=1.)+ facet_wrap( ~ 仪器序列号,ncol=2) + labs( title = "浓度与仪器关系", # 主标题 x = "测试日期", # X轴标签 y = "浓度1" )+ scale_fill_manual(values = c("red", "green")) + # 自定义颜色 theme_minimal() + theme( plot.title = element_text(size = 14, face = "bold", hjust = 0.5), axis.title.x = element_text(size = 12,face = "bold"), axis.title.y = element_text(size = 12,face = "bold"), axis.text.x = element_text(size = 8, face = "bold",angle=90) , panel.border = element_rect( color = "black", # 边框颜色 size = 1., # 边框粗细 linetype = "solid", # 线型(solid/dashed/dotted) fill = NA # 填充色(NA为透明) ), legend.position = "right") plot浓度1仪器Outlier plotC值仪器Outlier<-ggplot(df20Top4仪器Outlier)+geom_point(aes(testDay, C值),color="orange")+ geom_line(aes(testDay,C值移动均值),color="blue")+ geom_line(aes(testDay,C值累计均值),color="green",linewidth=1.)+ geom_line(aes(testDay,C值允许波动范围),color="red",linewidth=1.)+ facet_wrap( ~ 仪器序列号,ncol=2) + labs( title = "C值与仪器关系", # 主标题 x = "测试日期", # X轴标签 y = "C值" )+ scale_fill_manual(values = c("red", "green")) + # 自定义颜色 scale_y_log10()+ theme_minimal() + theme( plot.title = element_text(size = 14, face = "bold", hjust = 0.5), axis.title.x = element_text(size = 12,face = "bold"), axis.title.y = element_text(size = 12,face = "bold"), axis.text.x = element_text(size = 8, face = "bold",angle=90) , panel.border = element_rect( color = "black", # 边框颜色 size = 1., # 边框粗细 linetype = "solid", # 线型(solid/dashed/dotted) fill = NA # 填充色(NA为透明) ), legend.position = "right") plotC值仪器Outlier plotT值仪器Outlier<-ggplot(df20Top4仪器Outlier)+geom_point(aes(testDay, T值),color="orange")+ geom_line(aes(testDay,T值移动均值),color="blue")+ geom_line(aes(testDay,T值累计均值),color="green",linewidth=1.)+ geom_line(aes(testDay,T值允许波动范围),color="red",linewidth=1.)+ facet_wrap( ~ 仪器序列号,ncol=2) + labs( title = "T值与仪器关系", # 主标题 x = "测试日期", # X轴标签 y = "T值" )+ scale_fill_manual(values = c("red", "green")) + # 自定义颜色 scale_y_log10()+ theme_minimal() + theme( plot.title = element_text(size = 14, face = "bold", hjust = 0.5), axis.title.x = element_text(size = 12,face = "bold"), axis.title.y = element_text(size = 12,face = "bold"), axis.text.x = element_text(size = 8, face = "bold",angle=90) , panel.border = element_rect( color = "black", # 边框颜色 size = 1., # 边框粗细 linetype = "solid", # 线型(solid/dashed/dotted) fill = NA # 填充色(NA为透明) ), legend.position = "right") plotT值仪器Outlier plotToverC值仪器Outlier<-ggplot(df20Top4仪器Outlier)+geom_point(aes(testDay, ToverC值),color="orange")+ geom_line(aes(testDay,ToverC值移动均值),color="blue")+ geom_line(aes(testDay,ToverC值累计均值),color="green",linewidth=1.)+ geom_line(aes(testDay,ToverC值允许波动范围),color="red",linewidth=1.)+ facet_wrap( ~ 仪器序列号,ncol=2) + labs( title = "T/C值与仪器关系", # 主标题 x = "测试日期", # X轴标签 y = "T/C值" )+ scale_fill_manual(values = c("red", "green")) + # 自定义颜色 theme_minimal() + theme( plot.title = element_text(size = 14, face = "bold", hjust = 0.5), axis.title.x = element_text(size = 12,face = "bold"), axis.title.y = element_text(size = 12,face = "bold"), axis.text.x = element_text(size = 8, face = "bold",angle=90) , panel.border = element_rect( color = "black", # 边框颜色 size = 1., # 边框粗细 linetype = "solid", # 线型(solid/dashed/dotted) fill = NA # 填充色(NA为透明) ), legend.position = "right") plotToverC值仪器Outlier plot结论仪器Outlier<-ggplot(df20Top4仪器Outlier)+geom_point(aes(testDay, 是否阳性),color="orange")+ geom_line(aes(testDay,结论移动均值),color="blue")+ geom_line(aes(testDay,结论累计均值),color="green",linewidth=1.)+ geom_line(aes(testDay,结论允许波动范围),color="red",linewidth=1.)+ facet_wrap( ~ 仪器序列号,ncol=2) + labs( title = "结论/阳性率与仪器关系", # 主标题 x = "测试日期", # X轴标签 y = "结论/阳性率" )+ scale_fill_manual(values = c("red", "green")) + # 自定义颜色 theme_minimal() + theme( plot.title = element_text(size = 14, face = "bold", hjust = 0.5), axis.title.x = element_text(size = 12,face = "bold"), axis.title.y = element_text(size = 12,face = "bold"), axis.text.x = element_text(size = 8, face = "bold",angle=90) , panel.border = element_rect( color = "black", # 边框颜色 size = 1., # 边框粗细 linetype = "solid", # 线型(solid/dashed/dotted) fill = NA # 填充色(NA为透明) ), legend.position = "right") plot结论仪器Outlier } dev.off()