【问题标题】:Plot concentric pie charts in r在 r 中绘制同心饼图
【发布时间】:2018-06-01 01:59:58
【问题描述】:

我正在尝试制作同心饼图。内部饼图代表三类科目,每个类必须分成3个子类(当然子类的切片必须与相应的内部切片一致)。 这是我尝试过的:

layout(matrix(c(1,1,1,1,2,1,1,1,1), nrow=3)); pie(x=c(14,22,15,3,15,33,0,6,45),labels="",col=c("#f21c39","#dba814","#7309de")); pie(x=c(51,51,51),labels=c("O","VG","V"),col=c("#c64719","#0600f5","#089c1f"))

这行得通,但内部馅饼太小了。我尝试使用radius 选项,但外部切片与内部切片不对应。如何调整它们?

【问题讨论】:

    标签: r pie-chart


    【解决方案1】:

    在这种情况下,使用par(new=TRUE) 而不是layout() 来过度绘制饼图

    pie(x=c(14,22,15,3,15,33,0,6,45),labels="",
        col=c("#f21c39","#dba814","#7309de"))
    par(new=TRUE)
    pie(x=c(51,51,51),labels=c("O","VG","V"),radius=.5,
        col=c("#c64719","#0600f5","#089c1f"))
    

    【讨论】:

      【解决方案2】:

      三年后。这可以使用 sunburstR 包来实现。 http://timelyportfolio.github.io/sunburstR/example_baseball.html

      例子:

      DF <- data.frame(LOGRECNO = c(60, 61, 62, 63, 64, 65),
                   STATE = c(1, 1, 1, 1, 1, 1),
                   COUNTY = c(1, 1, 1, 1, 1, 1), 
                   TRACT = c(21100, 21100, 21100, 21100, 21100, 21100), 
                   BLOCK = c(1053, 1054, 1055, 1056, 1057, 1058))
      DF$BLOCKID <-
        paste(DF$LOGRECNO, DF$STATE, DF$COUNTY, 
              DF$TRACT, DF$BLOCK, sep = "-")
      
      DF %>% 
        select(BLOCKID) %>% 
        group_by(BLOCKID) %>% 
        summarise(Tots=n())->dftest
      
      sunburst(dftest)  
      

      我相信您可以根据自己的需要进行调整!

      【讨论】:

        【解决方案3】:

        你也可以使用 ggsunburst 包

        # install ggsunburst
        if (!require("ggplot2")) install.packages("ggplot2")
        if (!require("rPython")) install.packages("rPython")
        install.packages("http://genome.crg.es/~didac/ggsunburst/ggsunburst_0.0.9.tar.gz", repos=NULL, type="source")
        library(ggsunburst)
        
        df <- read.table(header=T, text = "
        parent node size
        O 1 14
        O 2 22
        O 3 15
        V 1 3
        V 2 15
        V 3 33
        VG 1 1
        VG 2 6
        VG 3 45")
        
        write.table(df, file = 'df.txt', sep = ',', row.names = F)
        
        sb <- sunburst_data('df.txt', type = "node_parent", sep = ",")
        p <- sunburst(sb, node_labels = T, leaf_labels = F, rects.fill.aes = "name")
        
        cols <- c("O" = "#c64719", "V" = "#0600f5", "VG" = "#089c1f", "1" = "#f21c39", "2" = "#dba814", "3" = "#7309de")
        p + scale_fill_manual(values = cols)
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2018-01-17
          • 2022-08-13
          • 1970-01-01
          • 1970-01-01
          • 2011-05-22
          • 2018-04-24
          • 1970-01-01
          相关资源
          最近更新 更多