ggplot(data = mpg, mapping = aes(x = displ, y = hwy)) + geom_point(mapping = aes(color = class)) + geom_smooth(data = filter(mpg, class == "subcompact"), se = FALSE)which causes the following error

Error in class == "subcompact" : comparison (1) is possible only for atomic and list typesI assume it worked when the authors wrote it, as they have a nice plot illustrating the results.

What is happening and how do I fix it? (R 3.3.2 on OS X)Thanks


*

The filter() function comes from the dplyr package. Be sure you"ve loaded it before running those lines. Otherwise, you"re running a comparison with class(), the built-in function, rather than mpg$class.

You are watching: Comparison (1) is possible only for atomic and list types


*

You probably had another package with a function (filter) loaded and masking dplyr filter

quick and dirty fix:

dplyr::filter()instead of

filter()

*

use library(dplyr)

library(dplyr)ggplot(data = mpg, mapping = aes(x = displ, y = hwy)) + geom_point(mapping = aes(color = class)) + geom_smooth( data = filter(mpg, class == "subcompact"), se = FALSE)

*

*

Thanks for contributing an answer to Stack Overflow!

Please be sure to answer the question. Provide details and share your research!

But avoid

Asking for help, clarification, or responding to other answers.Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.


Post Your Answer Discard

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy


Not the answer you're looking for? Browse other questions tagged r ggplot2 filter or ask your own question.




See more: Changes In Activity Have A(N) _________ Effect On Fixed Costs Per Unit.

site design / logo © 2021 Stack Exchange Inc; user contributions licensed under cc by-sa. rev2021.9.24.40305


Your privacy

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.