4

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())

picture of data_q_agg3

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!!!

adrisons
  • 3,443
  • 3
  • 32
  • 48
Luke Thompson
  • 41
  • 1
  • 2

3 Answers3

1

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" 
rempsyc
  • 785
  • 5
  • 24
0

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), ])

  • 1
    Hi Enzo, Welcome to Stack Overflow! First, I think your reply is spot-on, noting the challenges of reproducing the OP's problem and your suggested troubleshooting. Second, I think this doesn't quite make the cut for an "answer;" this would make a great comment if you had those privileges, but typically answers are a bit more complete (i.e. not just how to troubleshoot but a bit more about how you interpreted the error message, including your fix in the context of working code, etc.) – Michael Roswell Jun 14 '21 at 14:16
0

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

Chris Catignani
  • 5,040
  • 16
  • 42
  • 49
cancan
  • 1