How to get rid of "Error: Mapping should be created with `aes()` or `aes_()`."

I am trying to plot some figures using ggplot function but it keeps giving me this error and it is driving me crazy. I have checked my spelling and paranthesize. They are not the problem. Please see the below code and tell me what the problem is!!

 brfss2013 %>%
+     group_by(fmonth) %>%
+     summarise(mean_dv=mean(drvisits, na.rm=TRUE)) %>%
+     arrange(desc(mean_dv))
      ggplot(brfss2013, aes(x=factor(fmonth), y=mean_dv)) + geom_boxplot()

one problem may be that you do work to manipulate brfss2013 , but don't assign the result to any name so it is not available for future steps. I would guess mean_dv is therefore not there. but I would expect you to have a different error than the one shown.

The error shown might simply be a namespace confusion.
do

getAnywhere(aes)

This should show where aes is coming from which should be only

A single object matching ‘aes’ was found
It was found in the following places
  package:ggplot2
  namespace:ggplot2

if you have other things in there, thats your problem.
restart your rsession and load only the tidyverse and try again.

Thank you for your response.
I did getAnywhere(aes) and it gave me the answer you mentioned. "A single object ...".
Regarding assigning results to names I changed the code to

drvisits2013 <- brfss2013 %>%

  • group_by(fmonth) %>%
    
  • summarise(mean_dv=mean(drvisits, na.rm=TRUE)) %>%
    
  • ggplot(drvisits2013, aes(x=factor(fmonth), y=mean_dv))+
    
  • geom_boxplot()
    

But it gave me another error.
"Error in ggplot.default(., drvisits2013, aes(x = factor(fmonth), y = mean_dv)) :
object 'drvisits2013' not found"

Please let me know if you had other ideas.
Thanks,

You have an erroneous magrittr pipe between summarise and ggplot

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.