DkViolet, GrPink) that I can use in the 'bi_scale_fill' function? I am asking this because I am not having much luck tampering with the 'scale_fill_manual' function. May I kindly inquire how to go about creating my own custom color palettes (e.g. "Error in self$palette(n) : attempt to apply non-function.", which tells me that my usage of scale_fill_manual is wrong. However, this did not work, and I received an error message Geom_sf(data = data, mapping = aes(fill = bi_class), color = NA, size = 0.01, show.legend = FALSE) + scale_fill_manual(pal = bivariate_color_scale_2)` When creating the plots, I switched out the 'bi_scale_fill' function with 'scale_fill_manual'. R Code: Creating custom 3x3 color palette I intend to apply a custom 3 x 3 color palette adapted from the 'DkViolet' palette to suit my purposes. Package authors are free to evaluate formulas how ever they want, and the authors of the nlsLM() function decided to ignore the environment assigned to the formula.Thank you for the wonderful 'biscale' package. This works with the formula syntax (unquoted var names) and not the string because the formula can capture the environment.Īt least that's how it should work. NlsOutput <- lm(formula = myFormula, data = Data) #nlsOutput <- nlsLM(formula = myFormula, start = init, data = Data). So if you were using lm() rather than nlsLM, this would work with these two changes # myFormula <- "y ~ fitModel(x, a)". It can also be set with the function class : > bicycle <- 2 > class(bicycle).I still think it's better to create the formula directly.) Having a reference environment makes it easier to find functions used in a formula. It can be get (got) with the function class. (As noted by the as.formula() will capture the environment I skipped over that line when reading the code. The reason is that formulas capture their environment, strings do not. It's better to use myFormula <- y ~ fitModel(x, a) The first is using a string for a formula. # Other calculations done with fitModel() NlsOutput <- nlsLM(formula = myFormula, start = init, data = Data) ![]() # Minimum Working Example to reproduce error if we define "fitModel" and "obscureFunction" in R_GlobalEnv and call "obscureFunction" from the console. biScale (x, maxit 20, thresh 1e-09, row.center TRUE, row.scale TRUE, col.center TRUE, col.scale TRUE, trace FALSE) Arguments x matrix, possibly with NAs, also of class 'Incomplete' or 'sparseMatrix' format. I also don't understand why the original code works fine if the body of "topFunction" is run without calling it, i.e. ![]() I don't understand how "fitModel" can be evaluated in the environment of "fitModel" when the function can't be found in the calling environment of "obscureFunction", in other words I don't understand why this code change works. MyFormula <- "y ~ eval(fitModel(x, a), envir = environment(fitModel))" ![]() This I fixed by making the following change to "myFormula": DkViolet, GrPink) that I can use in the biscalefill function I am asking. After reading a thing or two on environments I think I understand why this is happening in this case, "fitModel" is not defined in the execution environment of "obscureFunction". May I kindly inquire how to go about creating my own custom color palettes (e.g. Running the script should yield the error, Error in eval(expr, envir, enclos) : could not find function "fitModel". The R code shown below is a minimal working example to reproduce an error that I can't say I understand.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |