'Error in UseMethod("rescale") : no applicable method for 'rescale' applied to an object of class "c('haven_labelled', 'vctrs_vctr', 'double')"
I am getting the following error:
Error in UseMethod("rescale") : no applicable method for 'rescale' applied to an object of class "c('haven_labelled', 'vctrs_vctr', 'double')"
Here is my code for the plot:
ggplot(data_q_agg3, aes(x = 'qmrcms', y = 'count', fill = 'qbncap')) + geom_col(position = "dodge")
data_q_agg3 was created by doing this (see picture):
data_q_agg3 <- group_by(na.omit(data_jointest), qbncap, qmrcms) %>%
summarise(count=n())

and data_jointest was created by doing this (just adding two data frames together):
data_jointest <- rbind(data_q_clean2, data_q_clean4, deparse.level = 0)
Finally, when trying to produce the plot, I get the following message/error:
Don't know how to automatically pick scale for object of type haven_labelled/vctrs_vctr/double. Defaulting to continuous.
Don't know how to automatically pick scale for object of type haven_labelled/vctrs_vctr/double. Defaulting to continuous.
Error in UseMethod("rescale") :
no applicable method for 'rescale' applied to an object of class "c('haven_labelled', 'vctrs_vctr', 'double')"`
Some help to fix this error would be really appreciated!!!
Solution 1:[1]
Not easy to reproduce... but I think you should first of all check your df for missing values (something like: df[!is.na(df$n), ])
Solution 2:[2]
I've experienced the same problem and solved it. The error was caused by the haven package creating incompatible class types. The solution was to change the variable class from c('haven_labelled', 'vctrs_vctr', 'double') to either factor or numeric, like this, e.g.,:
data_q_agg3$qbncap <- as.numeric(data_q_agg3$qbncap)
Or as factor:
data_q_agg3$qbncap <- as.factor(data_q_agg3$qbncap)
If you're not sure which variable is problematic, you can use the following to see the class of every variable you have at once:
sapply(data_q_agg3, class)
For example applied to mtcars dataset:
sapply(mtcars, class)
mpg cyl disp hp drat wt qsec vs
"numeric" "numeric" "numeric" "numeric" "numeric" "numeric" "numeric" "numeric"
am gear carb
"numeric" "numeric" "numeric"
Solution 3:[3]
I encountered the same error...
we just need to remove the ''
aes(x = qmrcms, y = count, fill = qbncap)
after I removed '' the error is gone and the plot was created successfully
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Enzo Loner |
| Solution 2 | RemPsyc |
| Solution 3 | Chris Catignani |
