Creating a half-donut, or parliamentary seating, chart

前端 未结 3 534
醉梦人生
醉梦人生 2021-02-06 07:38

I\'d like to create a chart displaying the size of the seats to a parliament, such as the one below, in ggplot2. My main problem is, essentially, how do I turn a donut chart to

3条回答
  •  北荒
    北荒 (楼主)
    2021-02-06 07:42

    Would this work for you?

    ggplot(df, aes(fill = Party, ymax = ymax, ymin = ymin, xmax = 2, xmin = 1)) + geom_rect() + 
      coord_polar(theta = "y",start=-pi/2) + xlim(c(0, 2)) + ylim(c(0,2))
    

    Basically you just set the ylim to be 2x your max so it only plots it on half. In this case we set the y limits to be from 0 to 2. Then you can offset the start in coord_polar(start=) to get it in proper place.

提交回复
热议问题