#| message: false
#| warning: false
library(dplyr)
library(pmplots)
data <- pmplots_data_obs()

data <- filter(data, ID <= 9*2)
data <- mutate(data, OCC = as.integer(TIME > 12))

head(data)

count(data, ID, OCC)

data1 <- filter(data, ID <= 9)

Chunk

pmplots:::chunk_by_cols(
  data, 
  cols = "ID", 
  id_per_chunk = 9
)
pmplots:::chunk_by_cols(
  data, 
  cols = "ID", 
  id_per_chunk = 3) %>% length()
pmplots:::chunk_by_cols(
  data, 
  cols = c("ID", "OCC"), 
  id_per_chunk = 3) %>% length()

Basic plot

Faceted by ID

ans <- dv_pred_ipred(
  data, 
  facets = "ID", 
  id_per_plot = 4, ncol = 2, 
  xlab  = "Time (hr)", 
  ylab = "Concentration (ng/ml)"
)

length(ans)

ans[1:2]

Faceted by ID and OCC

This has twice as many plots because every

ans <- dv_pred_ipred(
  data, 
  facets = c("ID", "OCC"),
  id_per_plot = 4, ncol = 2
)
length(ans)

ans[1:2]

Glue in better strip labels

ans <- dv_pred_ipred(
  data, 
  facets = c("ID//ID: {ID}", "OCC//Occasion: {OCC}"),
  id_per_plot = 4, ncol = 2
)

ans[1]

Lines

The plot will drop lines for PRED and IPRED in the plot and legend

dv_pred_ipred(data1, ipred_lty = 0, pred_lty = 0)[[1]]

Points

The plot will drop points for PRED and IPRED in the plot and legend

dv_pred_ipred(data1, ipred_point = FALSE, pred_point = FALSE)[[1]]

Colors

The plot will drop points for PRED and IPRED in the plot and legend

dv_pred_ipred(data1, ipred_color = "green4", pred_color = "orange3")[[1]]

Margin

dv_pred_ipred(
  data1, 
  plot.margin = margin(0, 2, 0, 0, unit = "in")
)[[1]]

Format the strip

dv_pred_ipred(
  data1, 
  strip.text = element_text(size = 5, margin = margin(3,0,3,0))
)[[1]]

Log y

dv_pred_ipred(data1, log_y = TRUE)[[1]]


metrumresearchgroup/pmplots documentation built on Oct. 15, 2024, noon