Anirban166 / GSoC21-Tests

Solutions for tests pertaining to directlabels improvements.
0 stars 0 forks source link

Using dlcompare instead of grid.arrange #8

Open Anirban166 opened 3 years ago

Anirban166 commented 3 years ago

Plot is not being drawn, weird:

Screenshot 2021-03-16 at 10 16 24 PM

Code:

library(ggplot2)
library(directlabels)
line.startpoint <- function(d, ...) {
  transform(gapply(d, subset, x == min(x)), hjust = 1)
}
line.endpoint <- function(d, ...) {
  transform(gapply(d, subset, x == max(x)), hjust = 0)
} 
alpha.data <- data.frame(size = c(1, 2, 3, 4, 5), power = c(1, 1.25, 1.75, 2.5, 3.5), category = "Alpha")
beta.data <- data.frame(size = c(1, 2, 3, 4, 5), power = c(1.5, 3, 5, 7.25, 9.5), category = "Beta")
gamma.data <- data.frame(size = c(1, 2, 3, 4, 5), power = c(2, 4, 6.5, 10, 13.5), category = "Gamma")
df <- rbind(alpha.data, beta.data, gamma.data)
g <- ggplot(df, aes(size, power, color = category)) + geom_line() + labs(x = "Particle Size", y = "Penetration Power")
dlcompare(list(lineplot.methods = g), pos.funs = list("line.startpoint", "line.endpoint"))

Melted data frame produces the same result:

library(ggplot2)
library(reshape2)
library(directlabels)
line.startpoint <- function(d, ...) {
  transform(gapply(d, subset, x == min(x)), hjust = 1)
}
line.endpoint <- function(d, ...) {
  transform(gapply(d, subset, x == max(x)), hjust = 0)
} 
alpha.data <- data.frame(size = c(1, 2, 3, 4, 5), power = c(1, 1.25, 1.75, 2.5, 3.5), type = "Alpha")
beta.data <- data.frame(size = c(1, 2, 3, 4, 5), power = c(1.5, 3, 5, 7.25, 9.5), type = "Beta")
gamma.data <- data.frame(size = c(1, 2, 3, 4, 5), power = c(2, 4, 6.5, 10, 13.5), type = "Gamma")
df <- rbind(alpha.data, beta.data, gamma.data)
longdf <- melt(df, id = "size")
names(longdf) <- c("size", "power", "type")
plots <- list(lineplot.methods = ggplot(longdf, aes(size, power , color = type)) + geom_line())
dlcompare(plots, list("line.endpoint", "line.startpoint"))
tdhock commented 3 years ago

I can't reproduce (works fine for me) with version

> sessionInfo()
R version 4.0.2 (2020-06-22)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 17134)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252 
[2] LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

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

other attached packages:
[1] reshape2_1.4.4         directlabels_2021.1.13 ggplot2_3.3.2         

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.5       magrittr_1.5     tidyselect_1.1.0 munsell_0.5.0   
 [5] colorspace_1.4-1 R6_2.5.0         rlang_0.4.7      quadprog_1.5-8  
 [9] stringr_1.4.0    plyr_1.8.6       dplyr_1.0.2      tools_4.0.2     
[13] grid_4.0.2       gtable_0.3.0     withr_2.4.1      ellipsis_0.3.1  
[17] digest_0.6.27    tibble_3.0.3     lifecycle_0.2.0  crayon_1.4.1    
[21] purrr_0.3.4      farver_2.0.3     vctrs_0.3.4      glue_1.4.2      
[25] labeling_0.3     stringi_1.5.3    compiler_4.0.2   pillar_1.4.6    
[29] generics_0.0.2   scales_1.1.1     pkgconfig_2.0.3 
> 
Anirban166 commented 3 years ago

@tdhock Thanks for checking! I had a feeling this is specific to me.
Here's my sessionInfo:

R version 4.0.3 (2020-10-10)
Platform: x86_64-apple-darwin19.6.0 (64-bit)
Running under: macOS Catalina 10.15.7

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /usr/local/Cellar/r/4.0.3_2/lib/R/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] directlabels_2021.1.13 ggplot2_3.3.2         

loaded via a namespace (and not attached):
 [1] rstudioapi_0.11  magrittr_1.5     tidyselect_1.1.0 munsell_0.5.0    colorspace_1.4-1 R6_2.4.1        
 [7] rlang_0.4.10     quadprog_1.5-8   dplyr_1.0.5      tools_4.0.3      grid_4.0.3       gtable_0.3.0    
[13] xfun_0.18        tinytex_0.26     withr_2.3.0      ellipsis_0.3.1   digest_0.6.27    tibble_3.0.3    
[19] lifecycle_1.0.0  crayon_1.3.4     purrr_0.3.4      farver_2.0.3     vctrs_0.3.6      glue_1.4.2      
[25] labeling_0.3     compiler_4.0.3   pillar_1.4.6     generics_0.1.0   scales_1.1.1     pkgconfig_2.0.3 

I can't seem to find out the reason why this is happening. Since its working for you, could you please show the output for the following code: (I'll use this in my test)

library(ggplot2)
library(directlabels)
line.startpoint <- function(d, ...) {
  transform(gapply(d, subset, x == min(x)), hjust = 1)
}
line.endpoint <- function(d, ...) {
  transform(gapply(d, subset, x == max(x)), hjust = 0)
} 
line.extremepoints <- dl.combine(line.startpoint, line.endpoint)
alpha.data <- data.frame(size = c(1, 2, 3, 4, 5), power = c(1, 1.25, 1.75, 2.5, 3.5), category = "Alpha")
beta.data <- data.frame(size = c(1, 2, 3, 4, 5), power = c(1.5, 3, 5, 7.25, 9.5), category = "Beta")
gamma.data <- data.frame(size = c(1, 2, 3, 4, 5), power = c(2, 4, 6.5, 10, 13.5), category = "Gamma")
df <- rbind(alpha.data, beta.data, gamma.data)
g <- ggplot(df, aes(size, power, color = category)) + geom_line() + xlim(0, 6) + labs(x = "Particle Size", y = "Penetration Power") + coord_cartesian(clip = "off")
dlcompare(list(lineplot.methods = g), list("line.startpoint", "line.endpoint", "line.extremepoints"))

It still shows no output for me:

Screenshot 2021-03-16 at 11 35 37 PM
tdhock commented 3 years ago

image maybe put this as a TODO investigate/debug this issue during GSOC?

Anirban166 commented 3 years ago

Thanks!

maybe put this as a TODO investigate/debug this issue during GSOC?

And yes, I was thinking that too - Done!