0

Trying to add a mean line for each group to bar chart. Receive same error each time:

Error in FUN(X[[i]], ...) : object 'Count' not found


ggplot(df_melted2  %>% 
         filter(EDNAME =='Blanchardstown-Corduff'), aes(Resource, Count, fill=Resource)) + 
  geom_bar(stat="identity", position = position_dodge()) +
  facet_wrap(~ EDNAME, scales = "free") +
  coord_flip() +
  theme(panel.background = element_blank())  +
  geom_point(data = df_melted2 %>% 
               group_by(Resource) %>% 
               summarise(Mean_Resource = mean(Count))) 

It works fine without the attempt to add the mean line:

ggplot(df_melted2  %>% 
         filter(EDNAME =='Blanchardstown-Corduff'), aes(Resource, Count, fill=Resource)) + 
  geom_bar(stat="identity", position = position_dodge()) +
  facet_wrap(~ EDNAME, scales = "free") +
  coord_flip() +
  theme(panel.background = element_blank()) 

Why is it not recognizing the column 'Count' and how did I get overall group mean lines in the chart?

enter image description here

1
  • Please dput(head(df_melted2 ,30)) and paste the result in the question. Commented Aug 6, 2020 at 19:48

1 Answer 1

1

Major oversight on my part. The summarized column must be the same name as the original and I had given it a new name.

ggplot(df_melted2  %>% 
         filter(EDNAME =='Blanchardstown-Corduff'), aes(Resource, Count, fill=Resource)) + 
  geom_bar(stat="identity", position = position_dodge()) +
  facet_wrap(~ EDNAME, scales = "free") +
  coord_flip() +
  theme(panel.background = element_blank())  +
  geom_point(data = df_melted2 %>% 
               group_by(Resource) %>% 
               summarise(***Count*** = mean(Count))) 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.