Install
Quick Start
Reference:
library(ggplot2) df <- data.frame( group = c ("Male" , "Female" , "Child" ), value = c (25 , 25 , 50 ) ) head(df)
group value1 Male 25 2 Female 25 3 Child 50
library(ggplot2) library(ggthemes) pie <- ggplot(df, aes(x="" , y=value, fill=group))+ geom_bar(width = 1 , stat = "identity" ) + coord_polar("y" , start=0 ) + theme_map() pie ggsave("pie.png" , w=3.17 , h=2.92 )
pie + scale_fill_manual(values=c ("#999999" , "#E69F00" , "#56B4E9" )) ggsave('pie2.png' , wi=4.6 , hei=3.76 )
pie + scale_fill_manual(values=c ("#999999" , "#E69F00" , "#56B4E9" )) + geom_text(aes(y = value/3 + c (0 , cumsum (value)[-length (value)]), label = paste(value*100 /sum (value),"%" , sep='' )))
Ring pie
pie + scale_fill_manual(values=c ("#999999" , "#E69F00" , "#56B4E9" )) + geom_text(aes(y = value/3 + c (0 , cumsum (value)[-length (value)]), label = paste(value*100 /sum (value),"%" , sep='' )))+ expand_limits(x=c (-1 ,1 ))
Multi-layer
TB = rbind(df,df) TB$Sub = c (10 ,15 ,15 ,15 ,10 ,35 ) TB$Group = c (rep ("A" ,3 ),rep ("B" ,3 )) ggplot(TB) + geom_bar(data=TB[1 :3 ,],aes(x="A" ,y=value[1 :3 ], fill=group),stat = 'identity' ) + geom_bar(aes(x="B" ,y =Sub, fill=Group),stat='identity' )+ coord_polar('y' )
Rose Plot
Reference: 九茶
library(ggplot2) dt = data.frame(A = c (2 , 7 , 4 , 10 , 1 ), B = c ('B' ,'A' ,'C' ,'D' ,'E' )) ggplot(dt, aes(x = B, y = log (1 +A), fill = B)) + geom_bar(stat = "identity" , alpha = 0.7 ) + coord_polar() + theme_light()
pie 3D
For pie3D, you’d like to install plotrix
first.
install.packages("plotrix" ) library("plotrix" ) x <-c (10 ,20 ,30 ,40 ,50 ) label <-c ("Alabama" , "Alaska" , "Arizona" ,"Arkansas" , "California" ) pie3D(x,labels=label,explode=0.1 ,main="PieChart of Countries " )
More
pie
author: 陈娜
© 陈娜 2015