【R语言 可视化】R语言 ggplot2 一张图画多个饼
来源:互联网 发布:js数组添加值 编辑:程序博客网 时间:2024/06/05 06:51
author:laidefa
date:2016-01-18
椰丝,终于画好了,要画好多个饼不容易啊 ,画都画饱了。
# data:2016-1-18# author:laidefarm(list=ls())gc()a=c(15,25,40,12,8)b=c(5,18,12,45,10)c=c(7,24,13,36,20)d=c(3,27,40,21,9)type=c("A","B","C","D","E")library(ggplot2)library(plyr)library(gridExtra)data1<- data.frame(a,type)data1<-arrange(data1,-a)data2<-data.frame(b,type)data2<-arrange(data2,-b)data3<-data.frame(c,type)data3<-arrange(data3,-c)data4<-data.frame(d,type)data4<-arrange(data4,-d)pie1<-ggplot(data1,aes(x=1,y=a,fill=type))+geom_bar(stat = "identity")+coord_polar(theta = "y")+ scale_fill_discrete(breaks=data1$type)+labs(title="Different Goods In Rate\n(2015)")+ theme(axis.title=element_blank(),axis.text=element_blank(),axis.ticks=element_blank())+ geom_text(aes(x=1.2,y=cumsum(a)-a/2,label=paste(type,":",round(a/sum(a)*100,2),"%")),size=4)pie2<-ggplot(data2,aes(x=1,y=b,fill=type))+geom_bar(stat = "identity")+coord_polar(theta = "y")+ scale_fill_discrete(breaks=data2$type)+labs(title="Different Goods In Rate\n(2015)")+ theme(axis.title=element_blank(),axis.text=element_blank(),axis.ticks=element_blank())+ geom_text(aes(x=1.2,y=cumsum(b)-b/2,label=paste(type,":",round(b/sum(b)*100,2),"%")),size=4)pie3<-ggplot(data3,aes(x=1,y=c,fill=type))+geom_bar(stat = "identity")+coord_polar(theta = "y")+ scale_fill_discrete(breaks=data3$type)+labs(title="Different Goods In Rate\n(2015)")+ theme(axis.title=element_blank(),axis.text=element_blank(),axis.ticks=element_blank())+ geom_text(aes(x=1.2,y=cumsum(c)-c/2,label=paste(type,":",round(c/sum(c)*100,2),"%")),size=4)pie4<-ggplot(data4,aes(x=1,y=d,fill=type))+geom_bar(stat = "identity")+coord_polar(theta = "y")+ scale_fill_discrete(breaks=data4$type)+labs(title="Different Goods In Rate\n(2015)")+ theme(axis.title=element_blank(),axis.text=element_blank(),axis.ticks=element_blank())+ geom_text(aes(x=1.2,y=cumsum(d)-d/2,label=paste(type,":",round(d/sum(d)*100,2),"%")),size=4)grid.arrange(pie1,pie2,pie3,pie4,ncol=2,nrow=2)
阅读全文
1 0
- 【R语言 可视化】R语言 ggplot2 一张图画多个饼
- 【R语言可视化】ggplot2 自定义柱状图
- R语言ggplot2画图
- R语言ggplot2饼状图
- R语言GGPlot2
- R语言数据可视化:ggplot2中的qplot()函数
- 基于ggplot2的R 语言数据可视化(一)
- [置顶]R语言 ggplot2包
- R语言 绘图 (ggplot2)
- R语言_car_可视化
- R语言地图可视化
- R语言数据可视化
- R语言之ggplot2绘图序列一
- R语言之ggplot2画图篇
- R语言之ggplot2画图篇
- R语言ggplot2包之画直方图
- R语言ggplot2包之画散点图
- R语言ggplot2包之注释
- 《Python核心编程》第1章答案
- java字节流边读边写
- 什么是框架?
- Unable to start adb server: error: protocol fault (couldn't read status): Connection reset by peer
- 将博客搬至CSDN
- 【R语言 可视化】R语言 ggplot2 一张图画多个饼
- 面向对象的JavaScript-1.语言特征
- 根据时间生成10位唯一性编码(最少9位)
- (HashMap,SparseArray,ArrayMap)
- Spark调优之Shuffle调优
- 【工具】Source Insight常用设置
- 城市选择插件
- python处理进制的转换
- Linux学习篇之---Ubuntu 14.04 重启后DNS配置丢失问题的解决方案,---ubuntu14.04