Skip to content

Commit

Permalink
Merge pull request #25 from nlmixr2/ggplot2-fix
Browse files Browse the repository at this point in the history
Work with updated ggplot2, and speed up testing
  • Loading branch information
mattfidler authored Nov 28, 2022
2 parents 70c52cb + 8463fb8 commit 85b40df
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 26 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ URL: https://github.com/nlmixr2/nlmixr2plot,
https://nlmixr2.github.io/nlmixr2plot/
BugReports: https://github.com/nlmixr2/nlmixr2plot/issues/
Imports:
ggplot2,
ggplot2 (>= 3.4.0),
nlmixr2est,
nlmixr2extra,
rxode2,
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
could use those names as the basis of figure captions (fix #8).
* Models without eta values (between subject variability) now have more
consistent plotting to models with eta values (fix #18).
* The package was updated to align with changes in ggplot2.

# nlmixr2plot 2.0.7

Expand Down
8 changes: 4 additions & 4 deletions R/plot.nlmixr2.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
}
ggplot2::ggplot(dataPlot, .aes) +
ggplot2::facet_wrap(~ind) +
ggplot2::geom_abline(slope = 1, intercept = 0, col = "red", size = 1.2) +
ggplot2::geom_abline(slope = 1, intercept = 0, col = "red", linewidth = 1.2) +
.logx +
.logy +
ggplot2::geom_point(alpha = 0.5) +
Expand Down Expand Up @@ -271,9 +271,9 @@ plotCmt <- function(x, cmt) {

.pIndividual <- ggplot2::ggplot(.d1, ggplot2::aes(x = .data$TIME, y = .data$DV)) +
ggplot2::geom_point() +
ggplot2::geom_line(ggplot2::aes(x = .data$TIME, y = .data$IPRED), col = "red", size = 1.2)
ggplot2::geom_line(ggplot2::aes(x = .data$TIME, y = .data$IPRED), col = "red", linewidth = 1.2)
if (any(names(.d1) == "PRED")) {
.pIndividual <- .pIndividual + ggplot2::geom_line(ggplot2::aes(x = .data$TIME, y = .data$PRED), col = "blue", size = 1.2)
.pIndividual <- .pIndividual + ggplot2::geom_line(ggplot2::aes(x = .data$TIME, y = .data$PRED), col = "blue", linewidth = 1.2)
}
.pIndividual <- .pIndividual + ggplot2::facet_wrap(~ID) +
ggplot2::ggtitle(cmt, sprintf("Individual Plots (%s of %s)", .j, length(.s))) +
Expand Down Expand Up @@ -374,7 +374,7 @@ traceplot.nlmixr2FitCore <- function(x, ...) {
if (!is.null(.niter)) {
.p0 <-
.p0 +
ggplot2::geom_vline(xintercept = .niter, col = "blue", size = 1.2)
ggplot2::geom_vline(xintercept = .niter, col = "blue", linewidth = 1.2)
}
.p0 <- .p0 + rxode2::rxTheme()
return(.p0)
Expand Down
2 changes: 1 addition & 1 deletion R/plot.nlmixr2AugPred.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ plot.nlmixr2AugPred <- function(x, y, ...) {
dpred <- d1[d1$ind != "Observed", ]
p3 <-
ggplot2::ggplot(d1, ggplot2::aes(.data$time, .data$values, col = .data$ind)) +
ggplot2::geom_line(data = dpred, size = 1.2) +
ggplot2::geom_line(data = dpred, linewidth = 1.2) +
ggplot2::geom_point(data = dobs) +
ggplot2::facet_wrap(~id) +
rxode2::rxTheme() +
Expand Down
51 changes: 31 additions & 20 deletions tests/testthat/test-plots-cens.R
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
test_that("plot censoring", {
skip_on_cran()

dat <- xgxr::case1_pkpd |>
dat <-
xgxr::case1_pkpd |>
dplyr::rename(DV=LIDV) |>
dplyr::filter(CMT %in% 1:2) |>
dplyr::filter(TRTACT != "Placebo")

doses <- unique(dat$DOSE)
nid <- 10 # 7 ids per dose group
dat2 <- do.call("rbind",
lapply(doses, function(x) {
ids <- dat |>
dplyr::filter(DOSE == x) |>
dplyr::summarize(ids=unique(ID)) |>
dplyr::pull()
ids <- ids[seq(1, nid)]
dat |>
dplyr::filter(ID %in% ids)
}))
dat2 <-
do.call(
"rbind",
lapply(doses, function(x) {
ids <- dat |>
dplyr::filter(DOSE == x) |>
dplyr::summarize(ids=unique(ID)) |>
dplyr::pull()
ids <- ids[seq(1, nid)]
dat |>
dplyr::filter(ID %in% ids)
})
)

## Use 2 compartment model
cmt2 <- function() {
Expand All @@ -44,19 +48,26 @@ test_that("plot censoring", {
}

## Check parsing
cmt2m <- nlmixr2est::nlmixr(cmt2)
suppressMessages(
cmt2m <- nlmixr2est::nlmixr(cmt2)
)

fit <-
nlmixr2est::nlmixr(
cmt2m, dat2, "saem",
control=list(print=0),
table=nlmixr2est::tableControl(cwres=TRUE, npde=TRUE)
)
suppressMessages(
fit <-
nlmixr2est::nlmixr(
cmt2m, dat2, "saem",
control=nlmixr2est::saemControl(print=0, nBurn = 10, nEm = 20),
table=nlmixr2est::tableControl(cwres=TRUE, npde=TRUE)
)
)

apo <- nlmixr2est::augPred(fit)
expect_error(plot(apo), NA)
expect_error(vpcPlot(fit, stratify="DOSE"), NA)
expect_error(vpcPlot(fit, pred_corr=TRUE, stratify="DOSE", log_y=TRUE), NA)
expect_error(vpcPlot(fit, stratify="DOSE", n = 10), NA)
expect_message(
vpcPlot(fit, pred_corr=TRUE, stratify="DOSE", log_y=TRUE, n = 10),
regexp = "Prediction-correction cannot be used together with censored data"
)

expect_error(plot(fit), NA)

Expand Down

0 comments on commit 85b40df

Please sign in to comment.