We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Essentially, the code below should return a <foo> class rcrd vector, not a mangled list.
<foo>
library(ggplot2) rcrd <- vctrs::new_rcrd(list(foo = LETTERS[1:3], bar = 1:3), class = "foo") p <- ggplot(mpg, aes(displ, hwy, colour = drv)) + geom_point() + scale_colour_manual( values = rcrd, na.value = NA ) options(max.print = 10) head(layer_data(p)$colour) #> Warning in ans[npos] <- rep(no, length.out = len)[npos]: number of items to #> replace is not a multiple of replacement length #> [[1]] #> [1] "B" "B" "B" "B" "B" "B" "B" "A" "A" "A" #> [ reached getOption("max.print") -- omitted 224 entries ] #> #> [[2]] #> [1] 2 2 2 2 2 2 2 1 1 1 #> [ reached getOption("max.print") -- omitted 224 entries ] #> #> [[3]] #> [1] "B" "B" "B" "B" "B" "B" "B" "A" "A" "A" #> [ reached getOption("max.print") -- omitted 224 entries ] #> #> [[4]] #> [1] 2 2 2 2 2 2 2 1 1 1 #> [ reached getOption("max.print") -- omitted 224 entries ] #> #> [[5]] #> [1] "B" "B" "B" "B" "B" "B" "B" "A" "A" "A" #> [ reached getOption("max.print") -- omitted 224 entries ] #> #> [[6]] #> [1] 2 2 2 2 2 2 2 1 1 1 #> [ reached getOption("max.print") -- omitted 224 entries ]
Created on 2024-09-20 with reprex v2.1.1
EDIT: It should work with a plain data.frame even.
library(ggplot2) pal_dataframe <- function(values) { force(values) function(n) { n_values <- vctrs::vec_size(values) if (n > n_values) { cli::cli_warn("Don't do this") } vctrs::vec_slice(values, seq_len(n)) } } df <- data.frame(foo = LETTERS[1:3], bar = 1:3) rownames(df) <- c("r", "4", "f") p <- ggplot(mpg, aes(displ, hwy, colour = drv)) + geom_point() + discrete_scale( "colour", palette = pal_dataframe(df) ) options(max.print = 10) head(layer_data(p)$colour) #> Error in `[.data.frame`(pal, match(as.character(x), names(pal))): undefined columns selected
The text was updated successfully, but these errors were encountered:
Oops posted this in the wrong repository, I apologise so much!
Sorry, something went wrong.
No branches or pull requests
Essentially, the code below should return a
<foo>
class rcrd vector, not a mangled list.Created on 2024-09-20 with reprex v2.1.1
EDIT: It should work with a plain data.frame even.
Created on 2024-09-20 with reprex v2.1.1
The text was updated successfully, but these errors were encountered: