用ggplot创建浮动饼图 [英] create floating pie charts with ggplot

查看:182
本文介绍了用ggplot创建浮动饼图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我正在使用浮动饼图作为其中一个绘图的报告。目前我使用plotrix软件包来绘制这个饼图。但是因为我对所有其他地块使用ggplot2,所以饼图看起来不同。所以我试图用ggplot2创建图。目前我有两个问题:


  1. ggplot饼图绘制在极坐标系统上。我想在笛卡尔协调系统上绘制多个饼图。目前我不知道该怎么做。


  2. 我希望能够控制笛卡尔坐标系上的馅饼半径。



  3. <$ p
    plot(1:5,type =n,xlab =x,ylab =y)
    floating.pie (2,3,c(1,3,5),半径= 0.5)
    floating.pie(4,2,c(2,4),半径= 0.2)
    floating.pie(4.5 ,4,c(3,2,5,1),radius = 0.3)

    感谢您的时间和帮助。

    解决方案


    1. 根据定义,饼图使用极坐标。您可以在使用笛卡尔坐标的另一个图形上叠加一些饼图,但它可能会很糟糕。事实上,无论如何,饼图总是很糟糕,所以要小心你想要的东西。

    2. coord_polar 页面。

    该代码中的重要一点是指定该半径映射到y美学。

      df < -  data.frame(
    variable = c(类似,不类似),
    值= c(80,20)

    ggplot(df,aes(x =,y = value,fill = variable))+
    geom_bar(width = 1,stat = identity)+
    scale_fill_manual(values = c(red,yellow))+
    coord_polar(y,start = 2 * pi / 3)+#< - 读取线!
    ggtitle(吃豆人)


    Currently I am working on report with a floating pie chart as one of the plots. Currently I use the plotrix package to plot this pie chart. But since I use ggplot2 for all the other plots, the pie plot looks different. So I'm trying to create the plot using ggplot2. Currently I have two issues:

    1. The ggplot pie charts are plotted on a polar coordination system. I want to plot multiple pie charts on Cartesian coordination system. At the moment I do not know how to do this.

    2. I want to be able to control the pie radius on the Cartesian coordination system.

    Here is the code I currently use:

    library("plotrix")
    plot(1:5, type="n", xlab="x", ylab="y")
    floating.pie(2, 3, c(1,3,5), radius=0.5)
    floating.pie(4, 2, c(2,4), radius=0.2)
    floating.pie(4.5, 4, c(3,2,5,1), radius=0.3)
    

    Thanks for your time and help.

    解决方案

    1. Pie charts by definition use polar coordinates. You could overlay some pie charts on another graph that used Cartesian coordinates but it would probably be awful. In fact, pie charts are mostly awful anyway, so be careful what you wish for.

    2. An example on the coord_polar page.

    The important bit in that code is specifying that radius maps to the "y" aesthetic.

     df <- data.frame(
       variable = c("resembles", "does not resemble"),
       value = c(80, 20)
     )
    ggplot(df, aes(x = "", y = value, fill = variable)) + 
      geom_bar(width = 1, stat = "identity") + 
      scale_fill_manual(values = c("red", "yellow")) + 
      coord_polar("y", start = 2 * pi / 3) +    #<- read this line!
      ggtitle("Pac man")
    

    这篇关于用ggplot创建浮动饼图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆