Skip to content

Commit

Permalink
Update 图3-3-1 不等宽柱形图.R
Browse files Browse the repository at this point in the history
  • Loading branch information
EasyChart authored Jun 3, 2019
1 parent 40c524e commit 5ac842e
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions 第3章_类别比较型图表/图3-3-1 不等宽柱形图.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@


#EasyCharts团队出品,如有商用必究,
#如需使用与深入学习,请联系微信:EasyCharts
#EasyCharts团队出品,
#如有问题修正与深入学习,可联系微信:EasyCharts

library(ggplot2)
library(Cairo)
Expand All @@ -12,18 +11,18 @@ mydata$xmin<-0
for (i in 2:5){
mydata$xmin[i]<-sum(mydata$Scale[1:i-1])
}
#构造矩形X轴的终点(最大点)
#构造矩形X轴的终点(最大点)
for (i in 1:5){
mydata$xmax[i]<-sum(mydata$Scale[1:i])
}
#构造数据标签的横坐标:
#构造数据标签的横坐标:
for (i in 1:5){
mydata$label[i]<-sum(mydata$Scale[1:i])-mydata$Scale[i]/2
}

#CairoPDF(file="不等宽柱形图.pdf",width=4.89,height=5.53)
#CairoPDF(file="不等宽柱形图.pdf",width=4.89,height=5.53)
#showtext.begin()
#windowsFonts(myFont = windowsFont("微软雅黑"))
#windowsFonts(myFont = windowsFont("微软雅黑"))
ggplot(mydata)+
geom_rect(aes(xmin=xmin,xmax=xmax,ymin=0,ymax=ARPU,fill=Name),colour="black",size=0.25)+
geom_text(aes(x=label,y=ARPU+3,label=ARPU),size=4,col="black")+
Expand All @@ -39,4 +38,4 @@ ggplot(mydata)+
legend.position="none"
)
#showtext.end()
#dev.off()
#dev.off()

0 comments on commit 5ac842e

Please sign in to comment.