美文网首页R语言学习
R006 基本图形-饼图pie()与扇形图fan.plot()

R006 基本图形-饼图pie()与扇形图fan.plot()

作者: caoqiansheng | 来源:发表于2020-08-11 00:01 被阅读0次

    饼图

    饼图可由函数pie()创建

    Usage
    
    pie(x, labels = names(x), edges = 200, radius = 0.8,
        clockwise = FALSE, init.angle = if(clockwise) 90 else 0,
        density = NULL, angle = 45, col = NULL, border = NULL,
        lty = NULL, main = NULL, ...)
    Arguments
    
    x   
    a vector of non-negative numerical quantities. The values in x are displayed as the areas of pie slices.
    labels  
    one or more expressions or character strings giving names for the slices. Other objects are coerced by as.graphicsAnnot. For empty or NA (after coercion to character) labels, no label nor pointing line is drawn.
    edges   
    the circular outline of the pie is approximated by a polygon with this many edges.
    radius  
    the pie is drawn centered in a square box whose sides range from -1 to 1. If the character strings labeling the slices are long it may be necessary to use a smaller radius.
    clockwise   
    logical indicating if slices are drawn clockwise or counter clockwise (i.e., mathematically positive direction), the latter is default.
    init.angle  
    number specifying the starting angle (in degrees) for the slices. Defaults to 0 (i.e., ‘3 o'clock’) unless clockwise is true where init.angle defaults to 90 (degrees), (i.e., ‘12 o'clock’).
    density 
    the density of shading lines, in lines per inch. The default value of NULL means that no shading lines are drawn. Non-positive values of density also inhibit the drawing of shading lines.
    angle   
    the slope of shading lines, given as an angle in degrees (counter-clockwise).
    col 
    a vector of colors to be used in filling or shading the slices. If missing a set of 6 pastel colours is used, unless density is specified when par("fg") is used.
    border, lty 
    (possibly vectors) arguments passed to polygon which draws each slice.
    main    
    an overall title for the plot.
    ... 
    graphical parameters can be given as arguments to pie. They will affect the main title and labels only.
    

     pie(rep(1, 24), col = rainbow(24), radius = 0.9)
    
    image.png

    扇形图

    饼图让比较各扇形的值变得困难(除非这些值被附加在标签上),为改善这种状况,我们创造了一种称为扇形图(fan.plot)的饼图变种。扇形图(Lemon& Tyagi,2009)提供了一种同时展示相对数量和相互差异的方法。在R中,扇形图是通过plotrix包中的fan.plot()函数实现的

    Usage
    
     fan.plot(x,edges=200,radius=1,col=NULL,align.at=NULL,max.span=NULL,
      labels=NULL,labelpos=NULL,label.radius=1.2,align="left",shrink=0.02,
      main="",ticks=NULL,include.sumx=FALSE,...)
    Arguments
    
    x   
    Vector of numbers.
    edges   
    The number of edges with which to draw a circle.
    radius  
    The radius of the sectors.
    col 
    The colors with which to fill the sectors.
    align.at    
    Where to align the sectors (see Details).
    max.span    
    The angle of the maximal sector in radians. The default is to scale x so that it sums to 2*pi.
    labels  
    Labels placed around the sector arcs.
    labelpos    
    Optional circumferential positions for the labels.
    label.radius    
    How far away from the sectors the labels will be placed. May be a vector with a radius for each label.
    align   
    Position of the alignment of sectors (see Details).
    shrink  
    How much to shrink each successive sector in user units.
    main    
    Optional title for the plot.
    ticks   
    The number of ticks that would appear if the sectors were on a pie chart. Default is no ticks, TRUE gives the number of ticks equal to the integer sum of x, which is fairly sensible if x is a vector of integers.
    include.sumx    
    Whether to include the sum of all x values as the largest sector.
    ... 
    Additional arguments passed to polygon.
    

    例:

    iucn.df<-data.frame(area=c("Africa","Asia","Europe","N&C America",
                               "S America","Oceania"),threatened=c(5994,7737,1987,4716,5097,2093))
    fan.plot(iucn.df$threatened,max.span=pi,
             labels=paste(iucn.df$area,iucn.df$threatened,sep="-"),
             main="Threatened species by geographical area (fan.plot)",ticks=276)
    
    image.png

    相关文章

      网友评论

        本文标题:R006 基本图形-饼图pie()与扇形图fan.plot()

        本文链接:https://www.haomeiwen.com/subject/pgusdktx.html