Giter Site home page Giter Site logo

Eta_Cats about ggpmx HOT 8 OPEN

ggpmxdevelopment avatar ggpmxdevelopment commented on June 13, 2024 1
Eta_Cats

from ggpmx.

Comments (8)

KZRKZR avatar KZRKZR commented on June 13, 2024

Hi @biethbr1
Please check findings/questions/solutions:

  1. cats.labels (+use.labels) does not work.
    Unfortunately in the current implementation, there were no possibilities to set strat.facet for these types of plots: eta_matrix, eta_cats, eta_conts. Not sure could we use cats.labels without strat.facet - will discover more.
  2. How to change covariate labels to full words?
    We could do it in different ways:

2.1 Workaround approach: by adding facet_grid function with labeller argument.

mlxpath <- file.path(system.file(package = "ggPMX"),
                     "testdata", "1_popPK_model", "project.mlxtran")
ctr <- pmx_mlxtran(mlxpath, config = "standing", settings = mySet)
ctr %>% pmx_plot_eta_cats(labels = list(title = "EBE vs discrete covariates")) +
  facet_grid(EFFECT~variable,
             labeller = labeller(
             variable=c('SEX'="Gender", 'RACE'="Race", 'DISE' = "Disease", 'ILOW' = "I low"),
             EFFECT=c('CL'= "first", 'F'= "second", 'Vc'= "third", 'Vp1'= "forth")
             ))

2.2 Make changes in existing code:

  • set strat = TRUE in eta_cov structure.
  • add code to plot_pmx.eta_cov function:
if (!is.null(x$facets)) 
          p <- p + facet_grid(stats::as.formula("EFFECT~variable"), scales = "free", labeller = x$facets$labeller)

Call will look like:

mySet=pmx_settings(is.draft=FALSE, use.abbrev = FALSE, use.labels = TRUE, 
                                      cats.labels = list(
                                        RACE = c("0"= "As", "1"="Bl"),
                                          variable=c('SEX'="Gender", 'RACE'="Race", 'DISE' = "Disease", 'ILOW' = "I low"),
                                          EFFECT=c('CL'= "first", 'F'= "second", 'Vc'= "third", 'Vp1'= "forth")
                                      )
                   )
mlxpath <- file.path(system.file(package = "ggPMX"),
                     "testdata","1_popPK_model","project.mlxtran")
ctr <- pmx_mlxtran(mlxpath, config = "standing", settings = mySet)

ctr %>% pmx_plot_eta_cats(labels = list(title = "EBE vs discrete covariates"))

Result:
image

2.3 I also see some comments in the code plot-eta-cov.R:

#' In case of pmx_plot_eta_cats and pmx_plot_eta_conts you can customize the covariates
#' and covaraites labels using pmx_cov.
Maybe someone could clarify this in details.

from ggpmx.

KZRKZR avatar KZRKZR commented on June 13, 2024
  1. How to specify symmetric ranges of y-axis different for each parameter?
    Could you please explain in detail how the result must looks like?
    Something like this:
    image

from ggpmx.

KZRKZR avatar KZRKZR commented on June 13, 2024
  1. Does not work to add hline.
    Will add changes to plot-eta-cov.R
    Call will be
    ctr %>% pmx_plot_eta_cats(labels = list(title = "EBE vs discrete covariates"), is.hline=TRUE, hline = 0.25)

from ggpmx.

baltcir1 avatar baltcir1 commented on June 13, 2024

About 3. Yes, this looks good!

from ggpmx.

KZRKZR avatar KZRKZR commented on June 13, 2024

About 3.
At first glance it possible to do with workaround:

library(facetscales)
library(dplyr)
library(ggplot2)
library(reshape)


ctr <- theophylline()
df <- ctr$data$eta
df <- df[, c(ctr$cats, "VALUE", "EFFECT"), with = FALSE]
max_y <- df %>%
  group_by(EFFECT) %>%
  summarise(
    maxValue = max(abs(VALUE), na.rm = T)
  ) %>%
  arrange(EFFECT)
get_scales_y <- function(i, scales_y = NULL){
  scales_i <- list(scale_y_continuous(limits = c(-max_y$maxValue[i], max_y$maxValue[i])))
  names(scales_i) <- max_y$EFFECT[i]
  append(scales_y, scales_i)
}
scales_y <- sapply(1:length(max_y$EFFECT), get_scales_y)
p <- ggplot(melt(df, measure.vars = ctr$cats)) +
  geom_boxplot(aes_string(x = "value", y = "VALUE"))
p + facet_grid_sc(stats::as.formula("EFFECT~variable"), scales = list(y = scales_y))

Will check how to implement this in ggPMX.
Do we plan to use this functionality in other charts? If yes, which exactly?

from ggpmx.

KZRKZR avatar KZRKZR commented on June 13, 2024

@baltcir1 Hi!
Are we good to introduce new dependency for implementation of symmetric ranges Y-axis - facetscales library (it is not on CRAN)?

from ggpmx.

KZRKZR avatar KZRKZR commented on June 13, 2024

Approach 2.3 seems like is the right way to manage labels.
This approach currently works for pmx_plot_eta_conts

mlxpath <- file.path(system.file(package = "ggPMX"),
                     "testdata","1_popPK_model","project.mlxtran")
ctr <- pmx_mlxtran(mlxpath, config = "standing")
ctr %>% pmx_plot_eta_conts(
  covariates=pmx_cov(values=list("HT0","TRT"),
                     labels=list("HT0 long","TRT long"))
)

After improvments will work for pmx_plot_eta_cats

mlxpath <- file.path(system.file(package = "ggPMX"),
                     "testdata","1_popPK_model","project.mlxtran")
ctr <- pmx_mlxtran(mlxpath, config = "standing")
ctr %>% pmx_plot_eta_cats(
  covariates=pmx_cov(values=list("RACE","DISE"),
                     labels=list("Race changed","Dise changed"))
)

from ggpmx.

baltcir1 avatar baltcir1 commented on June 13, 2024

from ggpmx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.