Skip to content

Commit 85b40df

Browse files
authored
Merge pull request #25 from nlmixr2/ggplot2-fix
Work with updated ggplot2, and speed up testing
2 parents 70c52cb + 8463fb8 commit 85b40df

5 files changed

Lines changed: 38 additions & 26 deletions

File tree

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ URL: https://github.com/nlmixr2/nlmixr2plot,
2121
https://nlmixr2.github.io/nlmixr2plot/
2222
BugReports: https://github.com/nlmixr2/nlmixr2plot/issues/
2323
Imports:
24-
ggplot2,
24+
ggplot2 (>= 3.4.0),
2525
nlmixr2est,
2626
nlmixr2extra,
2727
rxode2,

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
could use those names as the basis of figure captions (fix #8).
66
* Models without eta values (between subject variability) now have more
77
consistent plotting to models with eta values (fix #18).
8+
* The package was updated to align with changes in ggplot2.
89

910
# nlmixr2plot 2.0.7
1011

R/plot.nlmixr2.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
}
7070
ggplot2::ggplot(dataPlot, .aes) +
7171
ggplot2::facet_wrap(~ind) +
72-
ggplot2::geom_abline(slope = 1, intercept = 0, col = "red", size = 1.2) +
72+
ggplot2::geom_abline(slope = 1, intercept = 0, col = "red", linewidth = 1.2) +
7373
.logx +
7474
.logy +
7575
ggplot2::geom_point(alpha = 0.5) +
@@ -271,9 +271,9 @@ plotCmt <- function(x, cmt) {
271271

272272
.pIndividual <- ggplot2::ggplot(.d1, ggplot2::aes(x = .data$TIME, y = .data$DV)) +
273273
ggplot2::geom_point() +
274-
ggplot2::geom_line(ggplot2::aes(x = .data$TIME, y = .data$IPRED), col = "red", size = 1.2)
274+
ggplot2::geom_line(ggplot2::aes(x = .data$TIME, y = .data$IPRED), col = "red", linewidth = 1.2)
275275
if (any(names(.d1) == "PRED")) {
276-
.pIndividual <- .pIndividual + ggplot2::geom_line(ggplot2::aes(x = .data$TIME, y = .data$PRED), col = "blue", size = 1.2)
276+
.pIndividual <- .pIndividual + ggplot2::geom_line(ggplot2::aes(x = .data$TIME, y = .data$PRED), col = "blue", linewidth = 1.2)
277277
}
278278
.pIndividual <- .pIndividual + ggplot2::facet_wrap(~ID) +
279279
ggplot2::ggtitle(cmt, sprintf("Individual Plots (%s of %s)", .j, length(.s))) +
@@ -374,7 +374,7 @@ traceplot.nlmixr2FitCore <- function(x, ...) {
374374
if (!is.null(.niter)) {
375375
.p0 <-
376376
.p0 +
377-
ggplot2::geom_vline(xintercept = .niter, col = "blue", size = 1.2)
377+
ggplot2::geom_vline(xintercept = .niter, col = "blue", linewidth = 1.2)
378378
}
379379
.p0 <- .p0 + rxode2::rxTheme()
380380
return(.p0)

R/plot.nlmixr2AugPred.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ plot.nlmixr2AugPred <- function(x, y, ...) {
7171
dpred <- d1[d1$ind != "Observed", ]
7272
p3 <-
7373
ggplot2::ggplot(d1, ggplot2::aes(.data$time, .data$values, col = .data$ind)) +
74-
ggplot2::geom_line(data = dpred, size = 1.2) +
74+
ggplot2::geom_line(data = dpred, linewidth = 1.2) +
7575
ggplot2::geom_point(data = dobs) +
7676
ggplot2::facet_wrap(~id) +
7777
rxode2::rxTheme() +

tests/testthat/test-plots-cens.R

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
11
test_that("plot censoring", {
22
skip_on_cran()
33

4-
dat <- xgxr::case1_pkpd |>
4+
dat <-
5+
xgxr::case1_pkpd |>
56
dplyr::rename(DV=LIDV) |>
67
dplyr::filter(CMT %in% 1:2) |>
78
dplyr::filter(TRTACT != "Placebo")
89

910
doses <- unique(dat$DOSE)
1011
nid <- 10 # 7 ids per dose group
11-
dat2 <- do.call("rbind",
12-
lapply(doses, function(x) {
13-
ids <- dat |>
14-
dplyr::filter(DOSE == x) |>
15-
dplyr::summarize(ids=unique(ID)) |>
16-
dplyr::pull()
17-
ids <- ids[seq(1, nid)]
18-
dat |>
19-
dplyr::filter(ID %in% ids)
20-
}))
12+
dat2 <-
13+
do.call(
14+
"rbind",
15+
lapply(doses, function(x) {
16+
ids <- dat |>
17+
dplyr::filter(DOSE == x) |>
18+
dplyr::summarize(ids=unique(ID)) |>
19+
dplyr::pull()
20+
ids <- ids[seq(1, nid)]
21+
dat |>
22+
dplyr::filter(ID %in% ids)
23+
})
24+
)
2125

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

4650
## Check parsing
47-
cmt2m <- nlmixr2est::nlmixr(cmt2)
51+
suppressMessages(
52+
cmt2m <- nlmixr2est::nlmixr(cmt2)
53+
)
4854

49-
fit <-
50-
nlmixr2est::nlmixr(
51-
cmt2m, dat2, "saem",
52-
control=list(print=0),
53-
table=nlmixr2est::tableControl(cwres=TRUE, npde=TRUE)
54-
)
55+
suppressMessages(
56+
fit <-
57+
nlmixr2est::nlmixr(
58+
cmt2m, dat2, "saem",
59+
control=nlmixr2est::saemControl(print=0, nBurn = 10, nEm = 20),
60+
table=nlmixr2est::tableControl(cwres=TRUE, npde=TRUE)
61+
)
62+
)
5563

5664
apo <- nlmixr2est::augPred(fit)
5765
expect_error(plot(apo), NA)
58-
expect_error(vpcPlot(fit, stratify="DOSE"), NA)
59-
expect_error(vpcPlot(fit, pred_corr=TRUE, stratify="DOSE", log_y=TRUE), NA)
66+
expect_error(vpcPlot(fit, stratify="DOSE", n = 10), NA)
67+
expect_message(
68+
vpcPlot(fit, pred_corr=TRUE, stratify="DOSE", log_y=TRUE, n = 10),
69+
regexp = "Prediction-correction cannot be used together with censored data"
70+
)
6071

6172
expect_error(plot(fit), NA)
6273

0 commit comments

Comments
 (0)