【问题标题】:I want to create a double layered pie / donut chart in R我想在 R 中创建一个双层饼图/甜甜圈图
【发布时间】:2021-04-30 22:47:27
【问题描述】:

我正在尝试创建一个双层饼图,这是我的数据:

winner            <- c("White"   , "draw"    , "Black")
lowrated_scotch1  <- c(0.56617647, 0.04411765, 0.38970588) #winrate for Whites,Draws,Blacks in chess
highrated_scotch1 <- c(0.50000000, 0.03676471, 0.46323529)

为了提供更多背景信息,我试图根据我已经收集到的数据,在国际象棋中为苏格兰开局的高分/低分玩家可视化白/平/黑之间的胜率差异。

这就是我的想法:(图片取自谷歌图片)

layered pie chart example.

这是我的代码:

multi_layer_scotch<-data.frame(winner = c("White","draw","Black"),
                               Y = c(highrated_scotch),
                               X = c(lowrated_scotch))


ggplot(multi_layer_scotch, aes(x = X, y = Y, fill = winner))+
  geom_bar(stat = "identity")+
  scale_fill_manual(values = c("#769656","#baca44","#eeeed2"))+
  coord_polar(theta="y")+
  theme_void()

这就是我得到的输出:

my marvelous not complete graph

如您所见,图表并没有按照我想要的方式分层。我的情节中的 3 层应组装在一层(代表低收视率的玩家)与另一层(代表高收视率的玩家)堆叠。

我尝试按照这篇文章中给出的解决方案,但我自己无法做到,我觉得它有点不完整:Multi-level Pie Chart in R

如果您能帮我解决这个问题,我会很高兴!提前致谢

【问题讨论】:

    标签: r pie-chart gplots


    【解决方案1】:

    你的意思是这样的吗:

    df1 <- melt(multi_layer_scotch)
    ggplot(df1, aes(x = variable, y = value, fill = winner))+
      geom_bar(stat = "identity")+
      coord_polar(theta="y")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-13
      • 1970-01-01
      • 2016-06-03
      • 1970-01-01
      相关资源
      最近更新 更多