服务热线
178 0020 3020
学习设置dataframe每一列的名字
library(ggthemes) library(ggplot2) data <- read.csv("E:/R.4-1.csv", header = T) head(data) #V1 V2 V3 V4 #1 2 B 18 NA #2 3 C 16 NA #3 4 D 14 NA #4 5 E 12 NA #data <- data[,-4] #head(data) #V1 V2 V3 #1 2 B 18 #2 3 C 16 #3 4 D 14 #4 5 E 12 #colnames(data) <- c('city','code','value') #head(data) #city code value #1 2 B 18 #2 3 C 16 #3 4 D 14 #4 5 E 12 data1<-data[order(data$value,decreasing = TRUE),] myLabel=as.vector(data1$code) myLabel=paste(myLabel,"(",round(data1$value/sum(data1$value)*100,2),"%)",sep="") print(myLabel) ggplot(data1,aes(x="",y=value,fill=code))+ geom_bar(stat="identity",width=1)+ coord_polar(theta="y")+ labs(title="R2-02")+ theme(legend.position = 'top',legend.title=element_blank(),axis.ticks=element_blank())+ scale_fill_discrete(breaks=data1$code,labels=myLabel)
library(lattice) ggplot(singer,aes(x=voice.part,y=height,fill=voice.part))+ geom_boxplot()+ theme(legend.position ='top',legend.title = element_blank())+ labs(title="R2-02")
附件