Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting distorted curves when attempting to plot multiple curves in the same plot #3

Closed
eperkan opened this issue Dec 29, 2021 · 2 comments

Comments

@eperkan
Copy link

eperkan commented Dec 29, 2021

Thanks @albertopessia for this user-friendly and well-documented package.

When I try to plot multiple dose-response curves in the same plot, the curves get distorted - due to change(s) in x or y axes. Consider the following example:

# Data
dose <- c( -4, -4.30, -4.60, -4.90, -5.20, -5.50, -5.80, -6.10, -6.40, -6.70, -7)
response <- c(3, 10, 24, 32, 45, 58, 71, 88, 92, 95, 99)

# Model 1
m1 <- drda(formula = response ~ dose, mean_function = "logistic4")

# Model 2
low_bound <- c(0, 100, -7, -Inf)
up_bound <- c(0, 100, -4, Inf)
m2 <- drda(formula = response ~ log_dose, upper_bound = up_bound, lower_bound = low_bound)

# Plot
plot(m1, m2) 

example_1

Defining axis limits appears to be the only working solution:

plot(m, m2, 
        xlim = c(-7, .4), 
        ylim = c(0, 100), 
        legend = c("Model_1", "Model_2")) 

example_2

Is there something obvious I am missing here or is this the expected behavior?

> sessionInfo()
R version 4.0.2 (2020-06-22)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS  10.16

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] pracma_2.3.3 drda_1.0.0  

loaded via a namespace (and not attached):
 [1] fansi_0.5.0      assertthat_0.2.1 dplyr_1.0.7      crayon_1.4.1     utf8_1.2.2      
 [6] grid_4.0.2       R6_2.5.1         DBI_1.1.1        lifecycle_1.0.1  gtable_0.3.0    
[11] magrittr_2.0.1   scales_1.1.1     pillar_1.6.4     ggplot2_3.3.5    rlang_0.4.11    
[16] generics_0.1.0   vctrs_0.3.8      ellipsis_0.3.2   tools_4.0.2      glue_1.4.2      
[21] purrr_0.3.4      munsell_0.5.0    tinytex_0.34     xfun_0.26        compiler_4.0.2  
[26] pkgconfig_2.0.3  colorspace_2.0-2 tidyselect_1.1.1 tibble_3.1.5  
@albertopessia
Copy link
Owner

Hi @eperkan, thank you for your message.

When you call plot(m1, m2) the function is trying its best to automatically choose a good range for both axis. Sometimes, like in your case, it fails to find a good-looking option. The solution is to choose manually the preferred range, like you correctly guessed.

I have instead the following comments to your example:

  • m2 does not look a very good fit because of the growth rate range you chose. Try to fix only the minimum and maximum of the curve and leave the growth rate free to vary.
  • you can move the legend to a more convenient location using the argument legend_location, for example plot(m1, m2, xlim = c(-7, 1), legend = c("Model 1", "Model 2"), legend_location = "topright")

I hope my reply answers your questions.

Happy new year!

@albertopessia
Copy link
Owner

Closing the issue as no further comments were given.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants