0

I am new to R

I would like plot using ggplot2's geom_bar():

top_r_cuisine <- r_cuisine %>%
   group_by(Rcuisine) %>%
   summarise(count = n()) %>%
   arrange(desc(count)) %>%
   top_n(10)

enter image description here But when I try to plot this result by:

ggplot(top_r_cuisine, aes(x = Rcuisine)) +
       geom_bar()

I get this: enter image description here which doesn't represent the values in top_r_cuisine. Why?

EDIT: I have tried:

enter image description here

4
  • 3
    you need to tell it what y is: ggplot(top_r_cuisine, aes(x = Rcuisine, y = count)) + geom_bar(stat = "identity") Commented Oct 10, 2017 at 22:00
  • 1
    also, a screenshot of data isn't useful, it would be better to use dput(top_r_cuisine) and paste the output of that into your question. Commented Oct 10, 2017 at 22:02
  • @SymbolixAU I have tried with aes(x = Rcuisine, y = count) but I get the same result. Commented Oct 10, 2017 at 22:05
  • 1
    try geom_col instead of geom_bar or like @SymbolixAU suggested geom_bar(stat = "identity") Commented Oct 10, 2017 at 22:21

1 Answer 1

2
c_count=c(23,45,67,43,54)
country=c("america","india","germany","france","italy")
# sample Data frame #
finaldata = data.frame(country,c_count)
ggplot(finaldata, aes(x=country)) +
geom_bar(aes(weight = c_count))

you need to assign the weights in the geom_bar() enter image description here

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.