Skip to content

Commit

Permalink
Added some math to the plots for the linear models
Browse files Browse the repository at this point in the history
  • Loading branch information
mathesong committed Aug 21, 2024
1 parent dd62606 commit 5ae97c9
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 80 deletions.
36 changes: 17 additions & 19 deletions R/kinfitr_loganplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)) +
Expand Down Expand Up @@ -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))
Expand Down
8 changes: 6 additions & 2 deletions R/kinfitr_mlloganplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down Expand Up @@ -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)
Expand Down
35 changes: 13 additions & 22 deletions R/kinfitr_patlakplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)) +
Expand Down Expand Up @@ -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)
Expand Down
29 changes: 16 additions & 13 deletions R/kinfitr_refPatlak.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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))
Expand Down
44 changes: 28 additions & 16 deletions R/kinfitr_reflogan.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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))
Expand Down
20 changes: 12 additions & 8 deletions R/kinfitr_refmllogan.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit 5ae97c9

Please sign in to comment.