服务热线
178 0020 3020
#R4-1
library("ggplot2") mydata <- read.csv(file.choose()) str(mydata) View(mydata)
#使用order函数对数据框数据进行排序,将来可以从大到小进行饼图绘制
mydata$值 <-mydata$值/sum(mydata$值) mydata = mydata[order(mydata$值, decreasing = TRUE),] ggplot(data = mydata,aes(x = "",y = 值,fill = 代码 )) + #x shedingwei "" geom_bar(stat = "identity",width = 1,position = "fill") + coord_polar(theta = "y",start = 0,direction = -1) + theme(legend.position = 'top',legend.title = element_blank(), axis.text= element_blank(),axis.ticks =element_blank()) + labs(x = "value",y = "city",title = "R2-05 24/11/17")
当width< 1 时,可以画环形图。
ggplot(data = mydata,aes(x = "",y = 值,fill = 代码 )) + #x shedingwei "" geom_bar(stat = "identity",width = 0.2,position = "fill") + coord_polar(theta = "y",start = 0,direction = -1) + theme(legend.position = 'top',legend.title = element_blank(), axis.text= element_blank(),axis.ticks =element_blank()) + labs(x = "value",y = "city",title = "R2-05 24/11/17") + theme(panel.grid=element_blank()) + ## 去掉白色圆框和中间的坐标线 theme(panel.border=element_blank()) ## 去掉最外层正方形的框框
#R4-2
library("ggplot2") library("lattice") str(singer) ggplot(data = singer,aes(x = voice.part,y = height,fill = voice.part)) + geom_boxplot() + #theme adjust legned parameter theme(legend.position = 'top',legend.title=element_blank()) + labs(title = "R2-05 24/11/2017")
#about ggplot legend 图例
#http://blog.csdn.net/bone_ace/article/details/47284805
附件