R Language pie production

Pie
Pie looks better, but it is not as good as a bar graph type presentation of data, so most statisticians do not recommend Pie
Pie can function to create the format by PIE ()
PIE (the X-, Labels)
the X-a non-negative values the vector
labels label of x is
an example of a simple pie chart

slices <- c(10,12.4,16,8)
lbls <- c("US","UK","Australia","Germany","France")
pie(slices,labels = lbls,main="Simple Pie Chart",cex.names=0.5)

Here Insert Picture Description
2 example, the addition ratio of a value of a pie chart, a pie chart made percentage
using paste () function produced stitching tab string

#把slices中的数值改成此数值在此向量数值总和所占的百分比
x <- slices/sum(slices)*100
#signif指定数值的显示的位数,此例子显示的位数为3
y <- signif(x,digits = 3)
lbls2 <- paste(lbls," ",y,"%",sep="")
pie(x,lbls2,main="Simple Pie Chart",col = rainbow(length(lbls2)))

Here Insert Picture Description
Examples 3, 3D pie made
using plotrix package pie3D () function may create a 3D effect pie
wherein explode parameter represents the distance separating the sectors

ibrary(plotrix)
install.packages("plotrix")
#explode表示各个扇形分开的距离
pie3D(slices,labels=lbls,explode=0.1,main="Simple Pie Chart")

Here Insert Picture Description
Examples 4 to create a pie chart from the table
PIE () function only of parameter x may be a vector value may also be a table that is different from, and even barplot parameter x is a table format, it still needs to specify labels. Like just ahead of the x value table format does not advance its name
pie () function can automatically identify the values in the table

> mytable <- table(state.region)
> mytable
state.region
    Northeast         South North Central          West 
            9            16            12            13 
> lbls3 <- paste(names(mytable)," ",mytable,sep="")
> lbls3
[1] "Northeast 9"      "South 16"         "North Central 12" "West 13"         
> print(lbls3)
[1] "Northeast 9"      "South 16"         "North Central 12" "West 13"         
> pie(mytable,labels = lbls3,main = "Pie Chart from a Table\n (with sample sizes)")

Here Insert Picture Description
Examples 6, making the pie chart
pie sometimes does not agree to compare the size of each part, in this case can be performed by comparing the size of each part of FIG production sector
pie chart - it can show the number and relative size of each portion simultaneously the method of the difference
pie chart is (meaning meaning fan Chinese fan) is achieved by fan.plot plotrix package () function
pie chart with respect to the pie is different from a common portion of their respective common edge
so can easily differentiate the size of each part of the pattern

library(plotrix)
slices <- c(10,12.4,16,8)
lbls <- c("US","UK","Australia","Germany","France")
fan.plot(slices,labels = lbls,main="Fan plot")

Here Insert Picture Description
End summary
pie chart relative to the bar for more good-looking
but no bar more intuitive, it is generally not recommended statisticians Pie
function creating pie charts are three, one is often used pie () function
a package is plotrix pie3D () function can create 3D effects pie
final package is plotrix fan.plot () function can produce pie chart
function pIE () can be directly input form data values that can automatically identify which , pay attention to labels parameters which case you need to specify throw

Published 39 original articles · won praise 11 · views 10000 +

Guess you like

Origin blog.csdn.net/weixin_42712867/article/details/96088301