简体   繁体   English

R-ggplot2 geom_bar()无法正确绘制列的值

[英]R - ggplot2 geom_bar() doesn't plot correctly column's values

I am new to R 我是R新手

I would like plot using ggplot2 's geom_bar() : 我想使用ggplot2geom_bar()进行ggplot2

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

在此处输入图片说明 But when I try to plot this result by: 但是当我尝试通过以下方式绘制此结果时:

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

I get this: 我得到这个: 在此处输入图片说明 which doesn't represent the values in top_r_cuisine . 这不代表top_r_cuisine的值。 Why? 为什么?

EDIT: I have tried: 编辑:我尝试过:

在此处输入图片说明

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() 您需要在geom_bar()中分配权重 在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM