如何在R中绘制饼图

尼尔

我在 R 中有以下数据框,并想从中制作饼图

berth_day count
Friday    74
Monday    95
Saturday  126
Sunday    114
Thursday  62
Tuesday   85

我在 R 中跟随

ggplot(aes(x=berth_day, y=count))+
geom_bar(width =1)
+ coord_polar(theta = "y")

但是,它给了我以下错误

> ggplot(aes(x=berth_day, y=count))+
+   geom_bar(width =1)
Error: ggplot2 doesn't know how to deal with data of class uneval
>   + coord_polar(theta = "y")
Error in +coord_polar(theta = "y") : invalid argument to unary operator

我怎样才能在 R 中做到这一点?

阿克伦

不清楚 OP 的数据是来自管道还是忘记在ggplot调用中添加

df1N <- df1 %>% mutate(berth_day = factor(berth_day))

ggplot(df1N,  aes(x=berth_day, y=count, fill = berth_day))+
    geom_bar(width =1, stat = "identity")+ 
    coord_polar(theta = "y")

在此处输入图片说明

正如@GGamba 在评论中所说,geom_bar不推荐使用geom_col

ggplot(df1N,  aes(x=berth_day, y=count, fill = berth_day))+
    geom_col(width=1)+ 
    coord_polar(theta = "y")

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章