smouksassi / coveffectsplot

A Shiny App that Produce Forest Plots to Visualize Covariate Effects
Other
32 stars 17 forks source link

forest_plot shows an error when the PK parameter is not normalized: #9

Closed liangqiongyue closed 1 year ago

liangqiongyue commented 1 year ago

For example, the median AUC is 30, the confidence interval is (24, 36), and the Y-axis covariates are displayed only at the bottom of the drawing, not at equal intervals. How do you solve this problem?

library(coveffectsplot)
plotdata <- get_sample_data("forestplotdatacpidata.csv")
forest_plot(plotdata,
            ref_value = 30,
            ref_area = c(0.8, 1.2),
            x_facet_text_size = 12,
            y_facet_text_size = 12,
            y_label_text_size = 10,
            x_label_text_size = 10,
            table_text_size = 6,
            plot_table_ratio = 1.5,
            ref_legend_text = "Reference (vertical line)\n+/- 20% limits (colored area)",
            area_legend_text = "Reference (vertical line)\n+/- 20% limits (colored area)",
            xlabel = "Fold Change Relative to RHZE",
            facet_formula = "covname~paramname",
            table_position = "below",
            show_table_facet_strip = "both",
            show_table_yaxis_tick_label = TRUE)

image

smouksassi commented 1 year ago

try the new interface which is in github will make sure to fix for ref_value as well

library(ggplot2)
library(coveffectsplot)
#> Loading required package: data.table
#> Thank you for using coveffectsplot!
#> if you find it useful, please cite as:
#> JF Marier, N Teuscher and MS Mouksassi. Evaluation of covariate effects using forest plots and introduction to the coveffectsplot R package. CPT Pharmacometrics Syst Pharmacol. 2022;11:1283-1293. doi:10.1002/psp4.12829
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:data.table':
#> 
#>     between, first, last
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
plotdata <- get_sample_data("forestplotdatacpidata.csv")
forest_plot(plotdata,
            #ref_value = 30,
            ref_area = c(0.8, 1.2),
            x_facet_text_size = 12,
            y_facet_text_size = 12,
            y_label_text_size = 10,
            x_label_text_size = 10,
            table_text_size = 6,
            plot_table_ratio = 1.5,
            ref_legend_text = "Reference (vertical line)\n+/- 20% limits (colored area)",
            area_legend_text = "Reference (vertical line)\n+/- 20% limits (colored area)",
            xlabel = "Fold Change Relative to RHZE",
            facet_formula = "covname~paramname",
            table_position = "below",
            ref_value_by_panel = TRUE,
            ref_value_by_panel_data =as.data.frame(
                         plotdata %>%
                         distinct(paramname) %>%
                         mutate(xintercept=ifelse(paramname=="Alpha",30,30))),
            show_table_facet_strip = "both",
            show_table_yaxis_tick_label = TRUE)

Created on 2023-09-12 with reprex v2.0.2

smouksassi commented 1 year ago

please note the new interface dont support the area around different reference line by panel happy to consider adding it if you give me a use case and reproducible code you can always edit the ggplots after building the plot and play with the layers to put your area as the first layer

liangqiongyue commented 1 year ago

please note the new interface dont support the area around different reference line by panel happy to consider adding it if you give me a use case and reproducible code you can always edit the ggplots after building the plot and play with the layers to put your area as the first layer

I have now re-installed the coveffectsplot package from github and the issue is resolved. ref_area is also displayed, I don't know why, but thank you very much!

library(ggplot2)
remove.packages("coveffectsplot")
library(devtools)
install_github("smouksassi/coveffectsplot")
library(coveffectsplot)
#> Loading required package: data.table
#> Thank you for using coveffectsplot!
#> if you find it useful, please cite as:
#> JF Marier, N Teuscher and MS Mouksassi. Evaluation of covariate effects using forest plots and introduction to the coveffectsplot R package. CPT Pharmacometrics Syst Pharmacol. 2022;11:1283-1293. doi:10.1002/psp4.12829
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:data.table':
#> 
#>     between, first, last
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union

plotdata <- get_sample_data("forestplotdatacpidata.csv")
forest_plot(plotdata,
            ref_value = 30,
            ref_area = c(0.8, 1.2),
            x_facet_text_size = 12,
            y_facet_text_size = 12,
            y_label_text_size = 10,
            x_label_text_size = 10,
            table_text_size = 6,
            plot_table_ratio = 1.5,
            ref_legend_text = "Reference (vertical line)\n+/- 20% limits (colored area)",
            area_legend_text = "Reference (vertical line)\n+/- 20% limits (colored area)",
            xlabel = "Fold Change Relative to RHZE",
            facet_formula = "covname~paramname",
            table_position = "below",

            # ref_value_by_panel = TRUE,
            # ref_value_by_panel_data =as.data.frame(
            #   plotdata %>%
            #     distinct(paramname) %>%
            #     mutate(xintercept=ifelse(paramname=="Alpha",5,10))),
            show_table_facet_strip = "both",
            show_table_yaxis_tick_label = TRUE)

image

liangqiongyue commented 1 year ago

please note the new interface dont support the area around different reference line by panel happy to consider adding it if you give me a use case and reproducible code you can always edit the ggplots after building the plot and play with the layers to put your area as the first layer

Yes, the problem now is that I can't show area when I set different reference lines. If I want to show area, I can only use the same reference line.

Here is a use case and reproducible code, I would appreciate it if you could help me!

library(ggplot2)
# remove.packages("coveffectsplot")
library(devtools)
# install_github("smouksassi/coveffectsplot")
library(coveffectsplot)
#> Loading required package: data.table
#> Thank you for using coveffectsplot!
#> if you find it useful, please cite as:
#> JF Marier, N Teuscher and MS Mouksassi. Evaluation of covariate effects using forest plots and introduction to the coveffectsplot R package. CPT Pharmacometrics Syst Pharmacol. 2022;11:1283-1293. doi:10.1002/psp4.12829
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:data.table':
#> 
#>     between, first, last
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
#>     
# Data set for drawing reference lines and reference intervals
refdata <- data.frame(paramname=c("AUC0-24h", "AUCINF_obs", "Cmax"),
                      covname = "Ref",
                      label   = "62.5kg , 52y",
                      mid     = c(7.90085895292192, 27.1845907958493, 0.804185),
                      lower   = c(5.54472238420764, 18.1974874628107, 0.424805),
                      upper   = c(11.0014805878441, 40.308750975744, 1.5816375),
                      LABEL   = c("7.90 [5.54, 11.00]", "27.18 [18.20, 40.31]", "0.80 [0.42, 1.58]"))

plotdata <- data.frame(paramname=c("AUC0-24h", "AUC0-24h", "AUC0-24h", "AUC0-24h", "AUCINF_obs", 
                                   "AUCINF_obs", "AUCINF_obs", "AUCINF_obs", "Cmax", "Cmax", "Cmax", 
                                   "Cmax"),
                       covname = c("Age", "Age", "Weight", "Weight", "Age", "Age", "Weight", "Weight", 
                                   "Age", "Age", "Weight", "Weight"),
                       label   = c("18y", "85y", "45kg", "85kg", "18y", "85y", "45kg", "85kg", 
                                   "18y", "85y", "45kg", "85kg"),
                       mid     = c(12.1608125339694, 6.45711816381798, 10.8231769561981, 6.0219093721605, 
                                   27.9428298397278, 27.1069372987672, 34.8758452567289, 22.119474571285, 
                                   1.0226, 0.76471, 1.10465, 0.61234),
                       lower   = c(7.6375800991664, 4.52347184819706, 7.40245900052679, 4.04237782204439, 
                                   18.7341524659682, 18.0235871159371, 22.5117000801311, 14.8853908773828, 
                                   0.5013865, 0.39174925, 0.55885725, 0.317115),

                       upper   = c(16.8100885556605, 8.79457318281611, 15.0909800292925, 8.34838675699693, 
                                   40.8243333134091, 38.9749546431681, 51.8433385352901, 33.9041638721534, 
                                   1.85001, 1.552585, 2.2596, 1.1797225),
                       LABEL   = c("12.16 [7.64, 16.81]", "6.46 [4.52, 8.79]", "10.82 [7.40, 15.09]", 
                                   "6.02 [4.04, 8.35]", "27.94 [18.73, 40.82]", "27.11 [18.02, 38.97]", 
                                   "34.88 [22.51, 51.84]", "22.12 [14.89, 33.90]", "1.02 [0.50, 1.85]", 
                                   "0.76 [0.39, 1.55]", "1.10 [0.56, 2.26]", "0.61 [0.32, 1.18]"))

forest_plot(plotdata,
            # ref_value = 7.9,
            # ref_area = c(5.54/7.9, 11/7.9),
            facet_scales="free",
            # facet_space="free",
            x_facet_text_size = 12,
            y_facet_text_size = 12,
            y_label_text_size = 10,
            x_label_text_size = 10,
            table_text_size = 6,
            plot_table_ratio = 1.5,
            ref_legend_text = "Reference (vertical line)\n+/- 20% limits (colored area)",
            area_legend_text = "Reference (vertical line)\n+/- 20% limits (colored area)",
            xlabel = "Fold Change Relative to RHZE",
            facet_formula = "covname~paramname",
            table_position = "below",

            ref_value_by_panel = TRUE,
            ref_value_by_panel_data =as.data.frame(
              plotdata %>%
                distinct(paramname) %>%
                mutate(xintercept=ifelse(paramname=="AUC0-24h",7.9, 
                                  ifelse(paramname=="AUCINF_obs",27.18, 0.80)))),
            show_table_facet_strip = "both",
            show_table_yaxis_tick_label = TRUE)

image image

smouksassi commented 1 year ago

yes I fixed it ! perfect let me know if you have any other feature request !

smouksassi commented 1 year ago

I will see if I can fix the new interface with various ref and aeas in each panel question for you do you always use multiplicative areas like ref_value refareamin to rev_Valuerefareamax ? is there a use case where we want it to be addtion ?

smouksassi commented 1 year ago

just pushed another fix can you try again?

library(ggplot2)
library(coveffectsplot)
#> Loading required package: data.table
#> Thank you for using coveffectsplot!
#> if you find it useful, please cite as:
#> JF Marier, N Teuscher and MS Mouksassi. Evaluation of covariate effects using forest plots and introduction to the coveffectsplot R package. CPT Pharmacometrics Syst Pharmacol. 2022;11:1283-1293. doi:10.1002/psp4.12829
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:data.table':
#> 
#>     between, first, last
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
refdata <- data.frame(paramname=c("AUC0-24h", "AUCINF_obs", "Cmax"),
                      covname = "Ref",
                      label   = "62.5kg , 52y",
                      mid     = c(7.90085895292192, 27.1845907958493, 0.804185),
                      lower   = c(5.54472238420764, 18.1974874628107, 0.424805),
                      upper   = c(11.0014805878441, 40.308750975744, 1.5816375),
                      LABEL   = c("7.90 [5.54, 11.00]", "27.18 [18.20, 40.31]", "0.80 [0.42, 1.58]"))

plotdata <- data.frame(paramname=c("AUC0-24h", "AUC0-24h", "AUC0-24h", "AUC0-24h", "AUCINF_obs", 
                                   "AUCINF_obs", "AUCINF_obs", "AUCINF_obs", "Cmax", "Cmax", "Cmax", 
                                   "Cmax"),
                       covname = c("Age", "Age", "Weight", "Weight", "Age", "Age", "Weight", "Weight", 
                                   "Age", "Age", "Weight", "Weight"),
                       label   = c("18y", "85y", "45kg", "85kg", "18y", "85y", "45kg", "85kg", 
                                   "18y", "85y", "45kg", "85kg"),
                       mid     = c(12.1608125339694, 6.45711816381798, 10.8231769561981, 6.0219093721605, 
                                   27.9428298397278, 27.1069372987672, 34.8758452567289, 22.119474571285, 
                                   1.0226, 0.76471, 1.10465, 0.61234),
                       lower   = c(7.6375800991664, 4.52347184819706, 7.40245900052679, 4.04237782204439, 
                                   18.7341524659682, 18.0235871159371, 22.5117000801311, 14.8853908773828, 
                                   0.5013865, 0.39174925, 0.55885725, 0.317115),

                       upper   = c(16.8100885556605, 8.79457318281611, 15.0909800292925, 8.34838675699693, 
                                   40.8243333134091, 38.9749546431681, 51.8433385352901, 33.9041638721534, 
                                   1.85001, 1.552585, 2.2596, 1.1797225),
                       LABEL   = c("12.16 [7.64, 16.81]", "6.46 [4.52, 8.79]", "10.82 [7.40, 15.09]", 
                                   "6.02 [4.04, 8.35]", "27.94 [18.73, 40.82]", "27.11 [18.02, 38.97]", 
                                   "34.88 [22.51, 51.84]", "22.12 [14.89, 33.90]", "1.02 [0.50, 1.85]", 
                                   "0.76 [0.39, 1.55]", "1.10 [0.56, 2.26]", "0.61 [0.32, 1.18]"))

refdata <- as.data.frame( plotdata %>%
    distinct(paramname,covname) %>%
    mutate(xintercept=ifelse(paramname=="AUC0-24h",7.9, 
                             ifelse(paramname=="AUCINF_obs",27.18, 0.80))))

forest_plot(plotdata,
             facet_scales="free",
            x_facet_text_size = 12,
            y_facet_text_size = 12,
            y_label_text_size = 10,
            x_label_text_size = 10,
            table_text_size = 6,
            plot_table_ratio = 1.5,
            ref_area = c(0.5, 2),
            ref_legend_text = "Reference (vertical line)\n+/- 20% limits (colored area)",
            area_legend_text = "Reference (vertical line)\n+/- 20% limits (colored area)",
            xlabel = "Fold Change Relative to RHZE",
            facet_formula = "covname~paramname",
            table_position = "below",
            plot_title = "",combine_interval_shape_legend = TRUE,
            ref_value_by_panel = TRUE,
            show_ref_area = TRUE,show_ref_value = TRUE,
            ref_value_by_panel_data = refdata,
            show_table_facet_strip = "both",
            show_table_yaxis_tick_label = TRUE)

Created on 2023-09-12 with reprex v2.0.2

liangqiongyue commented 1 year ago

I will see if I can fix the new interface with various ref and aeas in each panel question for you do you always use multiplicative areas like ref_value refareamin to rev_Valuerefareamax ? is there a use case where we want it to be addtion ?

Yes, I often use multiplicative areas like ref_value*refareamin torev_Value*refareamax. But I feel that multiplication is also very convenient, addition and multiplication are actually similar, mainly depends on which one you like.I still feel respected that you have noticed this small need, thank you again.

liangqiongyue commented 1 year ago

just pushed another fix can you try again?

library(ggplot2)
library(coveffectsplot)
#> Loading required package: data.table
#> Thank you for using coveffectsplot!
#> if you find it useful, please cite as:
#> JF Marier, N Teuscher and MS Mouksassi. Evaluation of covariate effects using forest plots and introduction to the coveffectsplot R package. CPT Pharmacometrics Syst Pharmacol. 2022;11:1283-1293. doi:10.1002/psp4.12829
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:data.table':
#> 
#>     between, first, last
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
refdata <- data.frame(paramname=c("AUC0-24h", "AUCINF_obs", "Cmax"),
                      covname = "Ref",
                      label   = "62.5kg , 52y",
                      mid     = c(7.90085895292192, 27.1845907958493, 0.804185),
                      lower   = c(5.54472238420764, 18.1974874628107, 0.424805),
                      upper   = c(11.0014805878441, 40.308750975744, 1.5816375),
                      LABEL   = c("7.90 [5.54, 11.00]", "27.18 [18.20, 40.31]", "0.80 [0.42, 1.58]"))

plotdata <- data.frame(paramname=c("AUC0-24h", "AUC0-24h", "AUC0-24h", "AUC0-24h", "AUCINF_obs", 
                                   "AUCINF_obs", "AUCINF_obs", "AUCINF_obs", "Cmax", "Cmax", "Cmax", 
                                   "Cmax"),
                       covname = c("Age", "Age", "Weight", "Weight", "Age", "Age", "Weight", "Weight", 
                                   "Age", "Age", "Weight", "Weight"),
                       label   = c("18y", "85y", "45kg", "85kg", "18y", "85y", "45kg", "85kg", 
                                   "18y", "85y", "45kg", "85kg"),
                       mid     = c(12.1608125339694, 6.45711816381798, 10.8231769561981, 6.0219093721605, 
                                   27.9428298397278, 27.1069372987672, 34.8758452567289, 22.119474571285, 
                                   1.0226, 0.76471, 1.10465, 0.61234),
                       lower   = c(7.6375800991664, 4.52347184819706, 7.40245900052679, 4.04237782204439, 
                                   18.7341524659682, 18.0235871159371, 22.5117000801311, 14.8853908773828, 
                                   0.5013865, 0.39174925, 0.55885725, 0.317115),

                       upper   = c(16.8100885556605, 8.79457318281611, 15.0909800292925, 8.34838675699693, 
                                   40.8243333134091, 38.9749546431681, 51.8433385352901, 33.9041638721534, 
                                   1.85001, 1.552585, 2.2596, 1.1797225),
                       LABEL   = c("12.16 [7.64, 16.81]", "6.46 [4.52, 8.79]", "10.82 [7.40, 15.09]", 
                                   "6.02 [4.04, 8.35]", "27.94 [18.73, 40.82]", "27.11 [18.02, 38.97]", 
                                   "34.88 [22.51, 51.84]", "22.12 [14.89, 33.90]", "1.02 [0.50, 1.85]", 
                                   "0.76 [0.39, 1.55]", "1.10 [0.56, 2.26]", "0.61 [0.32, 1.18]"))

refdata <- as.data.frame( plotdata %>%
    distinct(paramname,covname) %>%
    mutate(xintercept=ifelse(paramname=="AUC0-24h",7.9, 
                             ifelse(paramname=="AUCINF_obs",27.18, 0.80))))

forest_plot(plotdata,
             facet_scales="free",
            x_facet_text_size = 12,
            y_facet_text_size = 12,
            y_label_text_size = 10,
            x_label_text_size = 10,
            table_text_size = 6,
            plot_table_ratio = 1.5,
            ref_area = c(0.5, 2),
            ref_legend_text = "Reference (vertical line)\n+/- 20% limits (colored area)",
            area_legend_text = "Reference (vertical line)\n+/- 20% limits (colored area)",
            xlabel = "Fold Change Relative to RHZE",
            facet_formula = "covname~paramname",
            table_position = "below",
            plot_title = "",combine_interval_shape_legend = TRUE,
            ref_value_by_panel = TRUE,
            show_ref_area = TRUE,show_ref_value = TRUE,
            ref_value_by_panel_data = refdata,
            show_table_facet_strip = "both",
            show_table_yaxis_tick_label = TRUE)

Created on 2023-09-12 with reprex v2.0.2

Yes, the results I ran are exactly the same as yours, very useful modification.