R - ggplot2 geom_bar()没有正确绘制列的值

时间:2021-04-12 15:01:20

I am new to R

我是R的新手

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

我想用ggplot2的geom_bar()进行绘图:

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

R  -  ggplot2 geom_bar()没有正确绘制列的值 But when I try to plot this result by:

但是,当我尝试通过以下方式绘制此结果:

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

I get this: R  -  ggplot2 geom_bar()没有正确绘制列的值 which doesn't represent the values in top_r_cuisine. Why?

我明白了:这不代表top_r_cuisine中的值。为什么?

EDIT: I have tried:

编辑:我试过:

R  -  ggplot2 geom_bar()没有正确绘制列的值

1 个解决方案

#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() R  -  ggplot2 geom_bar()没有正确绘制列的值

你需要在geom_bar中分配权重()

#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() R  -  ggplot2 geom_bar()没有正确绘制列的值

你需要在geom_bar中分配权重()