ggplot中多列的饼图图

问题描述 投票:0回答:1
 df>
 commodity China Australia India Thailand   ROW
      <chr>     <dbl>     <dbl> <dbl>    <dbl> <dbl>
    1 Cereals     4.6       8.2   4.4      4.7  78.2

我有这个df,我需要绘制这些变量的饼图(不包括第一个)

r dataframe pie-chart
1个回答
0
投票
您可能需要重塑数据,然后可以使用ggplot对其进行绘制,如下所示:

library(tidyverse) df %>% select(-commodity) %>% pivot_longer(cols = names(.)) %>% ggplot(aes(x = value, y = 1, fill = name)) + geom_col(position = "stack") + coord_polar() + theme_void()

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.