Hallo Github,
using the following replicable code, I ran into an interpolation issue when plotting directlabels;
#*************************************************************************************
library(tidyverse); library(directlabels); library(ggplot2);
#Generating some theoretical data
xgrid <-seq(0, 1, 0.05)
ygrid <- seq(0, 1, 0.05)
data.fit <- expand.grid(PA=xgrid,UA=ygrid)
zmatrix <- 2*((data.fit$PA*data.fit$UA)/(data.fit$PA+data.fit$UA))
zmatrix[1]<-0
zmatrix <- matrix(zmatrix, nrow=21, ncol = 21)
p<-as.data.frame(zmatrix) %>% #convert the matrix to data frame
rownames_to_column() %>% #get row coordinates
gather(key, value, -rowname) %>% #convert to long format
mutate(key = as.numeric(gsub("V", "", key)), #convert the column names to numbers
rowname = as.numeric(rowname)) #%>%
data.fit <- dplyr::bind_cols(data.fit,p)
#plotting a direct labels
a <- ggplot() +
geom_contour(data=data.fit,aes(x = UA, y = PA, z = value, colour = ..level..), linetype = "dotdash")+
geom_abline(slope = -1, intercept = 1, colour = "blue")+
theme_classic()+
labs(x = "UA", y = "PA")
a <-direct.label(a, list("far.from.others.borders", "calc.boxes", "enlarge.box",
box.color = NA, fill = "transparent", "draw.rects"))
a
#*************************************************************************************
A figure with similar "contours" as the following is expected;
However, I got the following error;
#*************************************************************************************
Error in approx(x, y) : need at least two non-NA values to interpolate
In addition: Warning messages:
1: In regularize.values(x, y, ties, missing(ties)) :
collapsing to unique 'x' values
2: In regularize.values(x, y, ties, missing(ties)) :
collapsing to unique 'x' values
3: In regularize.values(x, y, ties, missing(ties)) :
collapsing to unique 'x' values
4: In regularize.values(x, y, ties, missing(ties)) :
collapsing to unique 'x' values
5: In regularize.values(x, y, ties, missing(ties)) :
collapsing to unique 'x' values
6: In regularize.values(x, y, ties, missing(ties)) :
collapsing to unique 'x' values
7: In regularize.values(x, y, ties, missing(ties)) :
collapsing to unique 'x' values
8: In regularize.values(x, y, ties, missing(ties)) :
collapsing to unique 'x' values
#*************************************************************************************
I am currently running on the following specifications;
#*************************************************************************************
sessionInfo()
R version 3.6.3 (2020-02-29)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 17763)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252 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] directlabels_2020.6.17 forcats_0.5.0 stringr_1.4.0 dplyr_1.0.1
[5] purrr_0.3.4 readr_1.3.1 tidyr_1.1.1 tibble_3.0.3
[9] ggplot2_3.3.2 tidyverse_1.3.0
loaded via a namespace (and not attached):
[1] Rcpp_1.0.5 cellranger_1.1.0 pillar_1.4.6 compiler_3.6.3 dbplyr_1.4.4
[6] tools_3.6.3 digest_0.6.25 jsonlite_1.7.0 lubridate_1.7.9 lifecycle_0.2.0
[11] gtable_0.3.0 pkgconfig_2.0.3 rlang_0.4.7 reprex_0.3.0 cli_2.0.2
[16] DBI_1.1.0 rstudioapi_0.11 haven_2.3.1 withr_2.2.0 xml2_1.3.2
[21] httr_1.4.2 fs_1.5.0 generics_0.0.2 vctrs_0.3.2 hms_0.5.3
[26] isoband_0.2.2 grid_3.6.3 tidyselect_1.1.0 glue_1.4.1 R6_2.4.1
[31] fansi_0.4.1 readxl_1.3.1 farver_2.0.3 modelr_0.1.8 blob_1.2.1
[36] magrittr_1.5 backports_1.1.7 scales_1.1.1 ellipsis_0.3.1 rvest_0.3.6
[41] assertthat_0.2.1 colorspace_1.4-1 labeling_0.3 quadprog_1.5-8 stringi_1.4.6
[46] munsell_0.5.0 broom_0.7.0 crayon_1.3.4
#*************************************************************************************
What is the cause of this error?