How to make a sunburst plot in R or Python?

前端 未结 8 1638
梦如初夏
梦如初夏 2020-11-28 22:54

So far I have been unable to find an R library that can create a sunburst plot like those by John Stasko. Anyone knows how to accomplish that in R or Python?

8条回答
  •  被撕碎了的回忆
    2020-11-28 23:37

    You can create something along the lines of a sunburst plot using geom_tile from the ggplot2 package. Let's first create some random data:

    require(ggplot2); theme_set(theme_bw())
    require(plyr)
    dat = data.frame(expand.grid(x = 1:10, y = 1:10),
                     z = sample(LETTERS[1:3], size = 100, replace = TRUE))
    

    And then create the raster plot. Here, the x axis in the plot is coupled to the x variable in dat, the y axis to the y variable, and the fill of the pixels to the z variable. This yields the following plot:

    p = ggplot(dat, aes(x = x, y = y, fill = z)) + geom_tile() 
    print(p)
    

    enter image description here

    The ggplot2 package supports all kinds of coordinate transformations, one of which takes one axis and projects it on a circle, i.e. polar coordinates:

    p + coord_polar()
    

    enter image description here

    This roughly does what you need, now you can tweak dat to get the desired result.

提交回复
热议问题