From 5ae97c9ad891891a372b451b5d8815456f487ce5 Mon Sep 17 00:00:00 2001 From: mathesong Date: Wed, 21 Aug 2024 11:14:32 +0200 Subject: [PATCH] Added some math to the plots for the linear models --- R/kinfitr_loganplot.R | 36 ++++++++++++++++----------------- R/kinfitr_mlloganplot.R | 8 ++++++-- R/kinfitr_patlakplot.R | 35 ++++++++++++-------------------- R/kinfitr_refPatlak.R | 29 +++++++++++++++------------ R/kinfitr_reflogan.R | 44 ++++++++++++++++++++++++++--------------- R/kinfitr_refmllogan.R | 20 +++++++++++-------- 6 files changed, 92 insertions(+), 80 deletions(-) diff --git a/R/kinfitr_loganplot.R b/R/kinfitr_loganplot.R index 0f13930..0e71156 100644 --- a/R/kinfitr_loganplot.R +++ b/R/kinfitr_loganplot.R @@ -220,18 +220,16 @@ plot_Loganfit <- function(loganout, roiname = NULL) { xlimits <- c(0, tail(plotdf$Logan_Plasma, 1)) - xlabel <- "Integ(C_Plasma)/C_Tissue" - ylabel <- "Integ(C_Tissue)/C_Tissue" - - # xlabel <- expression(paste("", "", integral("", paste("0"), paste("", "t")), - # "C", phantom()[{paste("Plasma")}], "", - # phantom()/phantom(), "C", phantom()[{ - # paste("Tissue", "")}])) - # - # ylabel <- expression(paste("", "", integral("", paste("0"), paste("", "t")), - # "C", phantom()[{paste("Tissue")}], "", - # phantom()/phantom(), "C", phantom()[{ - # paste("Tissue", "")}])) + # xlabel <- "Integ(C_Plasma)/C_Tissue" + # ylabel <- "Integ(C_Tissue)/C_Tissue" + + xlabel <- expression(paste("", "", integral(, paste("0"), paste("", "t")), + "C", phantom()[{ paste("P") }],"(",tau,")d",tau, " / ", + "C", phantom()[{ paste("T") }],"(t)")) + + ylabel <- expression(paste("", "", integral(, paste("0"), paste("", "t")), + "C", phantom()[{ paste("T") }],"(",tau,")d",tau, " / ", + "C", phantom()[{ paste("T") }],"(t)")) outplot <- ggplot(data = plotdf, aes(x = Logan_Plasma, y = Logan_ROI, colour = Equilibrium)) + geom_point(aes(shape = "a", size = Weights)) + @@ -302,20 +300,20 @@ Logan_tstar <- function(t_tac, lowroi, medroi, highroi, input, filename = NULL, # ylabel <- "Integ(C_Tissue)/C_Tissue" xlabel <- expression(paste("", "", integral(, paste("0"), paste("", "t")), - "C", phantom()[{ paste("Plasma") }],"(t)", " / ", - "C", phantom()[{ paste("Tissue") }],"(t)")) + "C", phantom()[{ paste("P") }],"(",tau,")d",tau, " / ", + "C", phantom()[{ paste("T") }],"(t)")) ylabel <- expression(paste("", "", integral(, paste("0"), paste("", "t")), - "C", phantom()[{ paste("Tissue") }],"(t)", " / ", - "C", phantom()[{ paste("Tissue") }],"(t)")) + "C", phantom()[{ paste("T") }],"(",tau,")d",tau, " / ", + "C", phantom()[{ paste("T") }],"(t)")) low_xlimits <- c(0, tail(lowroi_fit$fitvals$Logan_Plasma, 1)) med_xlimits <- c(0, tail(medroi_fit$fitvals$Logan_Plasma, 1)) high_xlimits <- c(0, tail(highroi_fit$fitvals$Logan_Plasma, 1)) - low_linplot <- qplot(lowroi_fit$fitvals$Logan_Plasma, lowroi_fit$fitvals$Logan_ROI) + ggtitle("Low") + xlab(xlabel) + ylab(ylabel) + xlim(low_xlimits) - med_linplot <- qplot(medroi_fit$fitvals$Logan_Plasma, medroi_fit$fitvals$Logan_ROI) + ggtitle("Medium") + xlab(xlabel) + ylab(ylabel) + xlim(med_xlimits) - high_linplot <- qplot(highroi_fit$fitvals$Logan_Plasma, highroi_fit$fitvals$Logan_ROI) + ggtitle("High") + xlab(xlabel) + ylab(ylabel) + xlim(high_xlimits) + low_linplot <- qplot(lowroi_fit$fitvals$Logan_Plasma, lowroi_fit$fitvals$Logan_ROI) + ggtitle("Low") + xlim(low_xlimits) + xlab(xlabel) + ylab(ylabel) + med_linplot <- qplot(medroi_fit$fitvals$Logan_Plasma, medroi_fit$fitvals$Logan_ROI) + ggtitle("Medium") + xlim(med_xlimits) + xlab(xlabel) + ylab(ylabel) + high_linplot <- qplot(highroi_fit$fitvals$Logan_Plasma, highroi_fit$fitvals$Logan_ROI) + ggtitle("High") + xlim(high_xlimits) + xlab(xlabel) + ylab(ylabel) tstarInclFrames <- 3:frames zeros <- rep(0, length(tstarInclFrames)) diff --git a/R/kinfitr_mlloganplot.R b/R/kinfitr_mlloganplot.R index e3c9825..99ac11a 100644 --- a/R/kinfitr_mlloganplot.R +++ b/R/kinfitr_mlloganplot.R @@ -208,10 +208,14 @@ plot_mlLoganfit <- function(mlloganout, roiname = NULL) { names(myColors) <- levels(plotdf$Equilibrium) colScale <- scale_colour_manual(name = paste0(roiname, "\nEquilibrium"), values = myColors) + xlabel <- "Fitted Values" + ylabel <- expression(paste("", "", integral(, paste("0"), paste("", "t")), + "C", phantom()[{ paste("T") }],"(",tau,")d",tau)) + outplot <- ggplot(data = plotdf, aes(x = Fitted, y = Term1_DV, colour = Equilibrium)) + geom_point(aes(shape = "a", size = Weights)) + geom_abline(slope = 1, intercept = 0) + - xlab("Fitted Values") + ylab("Integ(C_Tissue)") + colScale + + xlab(xlabel) + ylab(ylabel) + colScale + guides(shape = "none", color = guide_legend(order = 1)) + scale_size(range = c(1, 3)) @@ -265,7 +269,7 @@ mlLogan_tstar <- function(t_tac, lowroi, medroi, highroi, input, filename = NULL xlabel <- "Fitted Values" ylabel <- expression(paste("", "", integral(, paste("0"), paste("", "t")), - "C", phantom()[{ paste("Tissue") }],"(t)")) + "C", phantom()[{ paste("T") }],"(",tau,")d",tau)) low_linplot <- qplot(lowroi_fit$fitvals$Fitted, lowroi_fit$fitvals$Term1_DV) + ggtitle("Low") + xlab(xlabel) + ylab(ylabel) med_linplot <- qplot(medroi_fit$fitvals$Fitted, medroi_fit$fitvals$Term1_DV) + ggtitle("Medium") + xlab(xlabel) + ylab(ylabel) diff --git a/R/kinfitr_patlakplot.R b/R/kinfitr_patlakplot.R index c3e6913..075ea23 100644 --- a/R/kinfitr_patlakplot.R +++ b/R/kinfitr_patlakplot.R @@ -203,18 +203,12 @@ plot_Patlakfit <- function(patlakout, roiname = NULL) { xlimits <- c(0, tail(plotdf$Patlak_Plasma, 1)) - xlabel <- "Integ(C_Plasma)/C_Tissue" - ylabel <- "Integ(C_Tissue)/C_Tissue" - - # xlabel <- expression(paste("", "", integral("", paste("0"), paste("", "t")), - # "C", phantom()[{paste("Plasma")}], "", - # phantom()/phantom(), "C", phantom()[{ - # paste("Plasma", "")}])) - # - # ylabel <- expression(paste("", "", integral("", paste("0"), paste("", "t")), - # "C", phantom()[{paste("Tissue")}], "", - # phantom()/phantom(), "C", phantom()[{ - # paste("Plasma", "")}])) + xlabel <- expression(paste("", "", integral(, paste("0"), paste("", "t")), + "C", phantom()[{ paste("P") }],"(",tau,")d",tau, " / ", + "C", phantom()[{ paste("P") }],"(t)")) + + ylabel <- expression(paste("C", phantom()[{ paste("T") }],"(t)", " / ", + "C", phantom()[{ paste("P") }],"(t)")) outplot <- ggplot(data = plotdf, aes(x = Patlak_Plasma, y = Patlak_ROI, colour = Equilibrium)) + geom_point(aes(shape = "a", size = Weights)) + @@ -272,20 +266,17 @@ Patlak_tstar <- function(t_tac, lowroi, medroi, highroi, input, filename = NULL, medroi_fit <- Patlakplot(t_tac, medroi, input, tstarIncludedFrames = frames, inpshift = inpshift, vB = vB, frameStartEnd = frameStartEnd) highroi_fit <- Patlakplot(t_tac, highroi, input, tstarIncludedFrames = frames, inpshift = inpshift, vB = vB, frameStartEnd = frameStartEnd) - #xlabel <- "Integ(C_Plasma) / C_Plasma" - #ylabel <- "C_Tissue / C_Plasma" - - xlabel <- expression(paste("", "", integral(, paste("0"), paste("", "t")), - "C", phantom()[{ paste("Plasma") }],"(t)", " / ", - "C", phantom()[{ paste("Plasma") }],"(t)")) - - ylabel <- expression(paste("C", phantom()[{ paste("Tissue") }],"(t)", " / ", - "C", phantom()[{ paste("Plasma") }],"(t)")) - low_xlimits <- c(0, tail(lowroi_fit$fitvals$Patlak_Plasma, 1)) med_xlimits <- c(0, tail(medroi_fit$fitvals$Patlak_Plasma, 1)) high_xlimits <- c(0, tail(highroi_fit$fitvals$Patlak_Plasma, 1)) + xlabel <- expression(paste("", "", integral(, paste("0"), paste("", "t")), + "C", phantom()[{ paste("P") }],"(",tau,")d",tau, " / ", + "C", phantom()[{ paste("P") }],"(t)")) + + ylabel <- expression(paste("C", phantom()[{ paste("T") }],"(t)", " / ", + "C", phantom()[{ paste("P") }],"(t)")) + low_linplot <- qplot(lowroi_fit$fitvals$Patlak_Plasma, lowroi_fit$fitvals$Patlak_ROI) + ggtitle("Low") + xlab(xlabel) + ylab(ylabel) + xlim(low_xlimits) med_linplot <- qplot(medroi_fit$fitvals$Patlak_Plasma, medroi_fit$fitvals$Patlak_ROI) + ggtitle("Medium") + xlab(xlabel) + ylab(ylabel) + xlim(med_xlimits) high_linplot <- qplot(highroi_fit$fitvals$Patlak_Plasma, highroi_fit$fitvals$Patlak_ROI) + ggtitle("High") + xlab(xlabel) + ylab(ylabel) + xlim(high_xlimits) diff --git a/R/kinfitr_refPatlak.R b/R/kinfitr_refPatlak.R index 44ca60b..2f9d20b 100644 --- a/R/kinfitr_refPatlak.R +++ b/R/kinfitr_refPatlak.R @@ -152,13 +152,20 @@ plot_refPatlakfit <- function(refpatlakout, roiname = NULL) { names(myColors) <- levels(plotdf$Equilibrium) colScale <- scale_colour_manual(name = paste0(roiname, "\nEquilibrium"), values = myColors) + ylabel <- expression(paste("C", phantom()[{ paste("T") }],"(t)", " / ", + "C", phantom()[{ paste("R") }],"(t)")) + + xlabel <- expression(paste("", "", integral(, paste("0"), paste("", "t")), + "C", phantom()[{ paste("R") }],"(",tau,")d",tau, " / ", + "C", phantom()[{ paste("R") }],"(t)")) + outplot <- ggplot(data = plotdf, aes(x = Patlak_ref, y = Patlak_roi, colour = Equilibrium)) + geom_point(aes(shape = "a", size = Weights)) + geom_abline( slope = as.numeric(refpatlakout$fit$coefficients[2]), intercept = as.numeric(refpatlakout$fit$coefficients[1]) ) + - xlab("Integ(C_Ref) / C_Ref") + ylab("C_Tissue / C_Ref") + colScale + + xlab(xlabel) + ylab(ylabel) + colScale + guides(shape = "none", color = guide_legend(order = 1)) + scale_size(range = c(1, 3)) return(outplot) @@ -200,20 +207,16 @@ refPatlak_tstar <- function(t_tac, reftac, lowroi, medroi, highroi, filename = N medroi_fit <- refPatlak(t_tac, reftac, medroi, length(reftac), frameStartEnd = frameStartEnd) highroi_fit <- refPatlak(t_tac, reftac, highroi, length(reftac), frameStartEnd = frameStartEnd) - patlak_xlab <- "Integ(C_Ref) / C_Ref" - patlak_ylab <- "C_Tissue / C_Ref" - - patlak_ylab <- expression(paste("C", phantom()[{ paste("Target") }],"(t)", " / ", - "C", phantom()[{ paste("Ref") }],"(t)")) - - patlak_xlab <- expression(paste("", "", integral(, paste("0"), paste("", "t")), - "C", phantom()[{ paste("Ref") }],"(t)", " / ", - "C", phantom()[{ paste("Ref") }],"(t)")) + ylabel <- expression(paste("C", phantom()[{ paste("T") }],"(t)", " / ", + "C", phantom()[{ paste("R") }],"(t)")) + xlabel <- expression(paste("", "", integral(, paste("0"), paste("", "t")), + "C", phantom()[{ paste("R") }],"(",tau,")d",tau, " / ", + "C", phantom()[{ paste("R") }],"(t)")) - low_linplot <- qplot(lowroi_fit$fitvals$Patlak_Ref, lowroi_fit$fitvals$Patlak_ROI) + ggtitle("Low") + xlab(patlak_xlab) + ylab(patlak_ylab) - med_linplot <- qplot(medroi_fit$fitvals$Patlak_Ref, medroi_fit$fitvals$Patlak_ROI) + ggtitle("Medium") + xlab(patlak_xlab) + ylab(patlak_ylab) - high_linplot <- qplot(highroi_fit$fitvals$Patlak_Ref, highroi_fit$fitvals$Patlak_ROI) + ggtitle("High") + xlab(patlak_xlab) + ylab(patlak_ylab) + low_linplot <- qplot(lowroi_fit$fitvals$Patlak_Ref, lowroi_fit$fitvals$Patlak_ROI) + ggtitle("Low") + xlab(xlabel) + ylab(ylabel) + med_linplot <- qplot(medroi_fit$fitvals$Patlak_Ref, medroi_fit$fitvals$Patlak_ROI) + ggtitle("Medium") + xlab(xlabel) + ylab(ylabel) + high_linplot <- qplot(highroi_fit$fitvals$Patlak_Ref, highroi_fit$fitvals$Patlak_ROI) + ggtitle("High") + xlab(xlabel) + ylab(ylabel) tstarInclFrames <- 3:frames zeros <- rep(0, length(tstarInclFrames)) diff --git a/R/kinfitr_reflogan.R b/R/kinfitr_reflogan.R index 75fcf09..73028bb 100644 --- a/R/kinfitr_reflogan.R +++ b/R/kinfitr_reflogan.R @@ -148,13 +148,25 @@ plot_refLoganfit <- function(refloganout, roiname = NULL) { names(myColors) <- levels(plotdf$Equilibrium) colScale <- scale_colour_manual(name = paste0(roiname, "\nEquilibrium"), values = myColors) + xlabel <- expression(paste("(", "", + paste(integral(, paste("0"), paste("", "t")), + "C", phantom()[{ paste("R") }],"(",tau,")d",tau, " + ", + frac(paste("C", phantom()[{ paste("R") }],"(t)"), + paste("k",phantom()[{ paste("2") }],"\'",))),")", + " / ", + "C", phantom()[{ paste("T") }],"(t)")) + + ylabel <- expression(paste("", "", integral(, paste("0"), paste("", "t")), + "C", phantom()[{ paste("T") }],"(",tau,")d",tau, " / ", + "C", phantom()[{ paste("T") }],"(t)")) + outplot <- ggplot(data = plotdf, aes(x = Logan_ref, y = Logan_roi, colour = Equilibrium)) + geom_point(aes(shape = "a", size = Weights)) + geom_abline( slope = as.numeric(refloganout$fit$coefficients[2]), intercept = as.numeric(refloganout$fit$coefficients[1]) ) + - xlab("[Integ(C_Ref)+C_Ref/k2prime] / C_Tissue") + ylab("Integ(C_Tissue) / C_Tissue") + colScale + + xlab(xlabel) + ylab(ylabel) + colScale + guides(shape = "none", color = guide_legend(order = 1)) + scale_size(range = c(1, 3)) return(outplot) @@ -198,21 +210,21 @@ refLogan_tstar <- function(t_tac, reftac, lowroi, medroi, highroi, k2prime, file medroi_fit <- refLogan(t_tac, reftac, medroi, k2prime, length(reftac), frameStartEnd = frameStartEnd) highroi_fit <- refLogan(t_tac, reftac, highroi, k2prime, length(reftac), frameStartEnd = frameStartEnd) - # logan_xlab <- "[Integ(C_Ref)+C_Ref/k2prime] / C_Tissue" - # logan_ylab <- "Integ(C_Tissue) / C_Tissue" - - logan_xlab <- expression(paste("(", "", integral(, paste("0"), paste("", "t")), - "C", phantom()[{ paste("Ref") }],"(t)", " + ", - "C", phantom()[{ paste("Ref") }],"(t)","/k",phantom()[{ paste("2") }],"\' ) / ", - "C", phantom()[{ paste("Target") }],"(t)")) - - logan_ylab <- expression(paste("", "", integral(, paste("0"), paste("", "t")), - "C", phantom()[{ paste("Tissue") }],"(t)", " / ", - "C", phantom()[{ paste("Tissue") }],"(t)")) - - low_linplot <- qplot(lowroi_fit$fitvals$Logan_Ref, lowroi_fit$fitvals$Logan_ROI) + ggtitle("Low") + xlab(logan_xlab) + ylab(logan_ylab) - med_linplot <- qplot(medroi_fit$fitvals$Logan_Ref, medroi_fit$fitvals$Logan_ROI) + ggtitle("Medium") + xlab(logan_xlab) + ylab(logan_ylab) - high_linplot <- qplot(highroi_fit$fitvals$Logan_Ref, highroi_fit$fitvals$Logan_ROI) + ggtitle("High") + xlab(logan_xlab) + ylab(logan_ylab) + xlabel <- expression(paste("(", "", + paste(integral(, paste("0"), paste("", "t")), + "C", phantom()[{ paste("R") }],"(",tau,")d",tau, " + ", + frac(paste("C", phantom()[{ paste("R") }],"(t)"), + paste("k",phantom()[{ paste("2") }],"\'",))),")", + " / ", + "C", phantom()[{ paste("T") }],"(t)")) + + ylabel <- expression(paste("", "", integral(, paste("0"), paste("", "t")), + "C", phantom()[{ paste("T") }],"(",tau,")d",tau, " / ", + "C", phantom()[{ paste("T") }],"(t)")) + + low_linplot <- qplot(lowroi_fit$fitvals$Logan_Ref, lowroi_fit$fitvals$Logan_ROI) + ggtitle("Low") + xlab(xlabel) + ylab(ylabel) + med_linplot <- qplot(medroi_fit$fitvals$Logan_Ref, medroi_fit$fitvals$Logan_ROI) + ggtitle("Medium") + xlab(xlabel) + ylab(ylabel) + high_linplot <- qplot(highroi_fit$fitvals$Logan_Ref, highroi_fit$fitvals$Logan_ROI) + ggtitle("High") + xlab(xlabel) + ylab(ylabel) tstarInclFrames <- 3:frames zeros <- rep(0, length(tstarInclFrames)) diff --git a/R/kinfitr_refmllogan.R b/R/kinfitr_refmllogan.R index f6617e0..42d061f 100644 --- a/R/kinfitr_refmllogan.R +++ b/R/kinfitr_refmllogan.R @@ -162,10 +162,15 @@ plot_refmlLoganfit <- function(refmlloganout, roiname = NULL) { names(myColors) <- levels(plotdf$Equilibrium) colScale <- scale_colour_manual(name = paste0(roiname, "\nEquilibrium"), values = myColors) + xlabel <- "Fitted Values" + + ylabel <- expression(paste("", "", integral(, paste("0"), paste("", "t")), + "C", phantom()[{ paste("T") }],"(",tau,")d",tau)) + outplot <- ggplot(data = plotdf, aes(x = Fitted, y = Term1_DV, colour = Equilibrium)) + geom_point(aes(shape = "a", size = Weights)) + geom_abline(slope = 1, intercept = 0) + - xlab("Fitted Values") + ylab("Integ(C_Tissue)") + colScale + + xlab(xlabel) + ylab(ylabel) + colScale + guides(shape = "none", color = guide_legend(order = 1)) + scale_size(range = c(1, 3)) return(outplot) @@ -212,15 +217,14 @@ refmlLogan_tstar <- function(t_tac, reftac, lowroi, medroi, highroi, k2prime, fi medroi_fit <- refmlLogan(t_tac, reftac, medroi, k2prime, length(reftac), frameStartEnd = frameStartEnd) highroi_fit <- refmlLogan(t_tac, reftac, highroi, k2prime, length(reftac), frameStartEnd = frameStartEnd) - mllogan_xlab <- "Fitted Values" - # mllogan_ylab <- "Integ(C_Tissue)" + xlabel <- "Fitted Values" - mllogan_ylab <- expression(paste("", "", integral(, paste("0"), paste("", "t")), - "C", phantom()[{ paste("Tissue") }],"(t)")) + ylabel <- expression(paste("", "", integral(, paste("0"), paste("", "t")), + "C", phantom()[{ paste("T") }],"(",tau,")d",tau)) - low_linplot <- qplot(lowroi_fit$fitvals$Fitted, lowroi_fit$fitvals$Term1_DV) + ggtitle("Low") + xlab(mllogan_xlab) + ylab(mllogan_ylab) - med_linplot <- qplot(medroi_fit$fitvals$Fitted, medroi_fit$fitvals$Term1_DV) + ggtitle("Medium") + xlab(mllogan_xlab) + ylab(mllogan_ylab) - high_linplot <- qplot(highroi_fit$fitvals$Fitted, highroi_fit$fitvals$Term1_DV) + ggtitle("High") + xlab(mllogan_xlab) + ylab(mllogan_ylab) + low_linplot <- qplot(lowroi_fit$fitvals$Fitted, lowroi_fit$fitvals$Term1_DV) + ggtitle("Low") + xlab(xlabel) + ylab(ylabel) + med_linplot <- qplot(medroi_fit$fitvals$Fitted, medroi_fit$fitvals$Term1_DV) + ggtitle("Medium") + xlab(xlabel) + ylab(ylabel) + high_linplot <- qplot(highroi_fit$fitvals$Fitted, highroi_fit$fitvals$Term1_DV) + ggtitle("High") + xlab(xlabel) + ylab(ylabel) tstarInclFrames <- 3:frames zeros <- rep(0, length(tstarInclFrames))