查看原文
其他

R作图也是杠杠的(1)

2017-09-01 miffery 临床科研与meta分析
> city1 <- c(30.34, 34.98, 25.58, 6.48, 2.43) > city2 <- c(37.49, 35.56, 17.99, 6.56, 2.65) > label<-c("a","b","c","d","e") > percent1<-round(city1/sum(city1)*100,digits = 2) > label1<-paste(label,percent1," ")> label1<-paste(label,percent1,sep=" ")> label1<-paste(label1,"%",sep="")> pie(city1,init.angle = 180,labels=label1,xlab="city1",clockwise = T,border = F,col = gray(seq(0.9,0.3,length=6)))


> label2<-paste(label2,"%",sep="")> pie(city2,init.angle = 270,labels = label2,clockwise = F,border = T,col = gray(seq(0.3,0.9,length=6)))


> yy<-matrix(c(city1/sum(city1)*100,city2/sum(city2)*100),ncol = 2)> yy [,1] [,2] [1,] 30.397756 37.396509 [2,] 35.046589 35.471322 [3,] 25.628695 17.945137 [4,] 6.492335 6.543641 [5,] 2.434626 2.643392 > dimnames(yy)<-list(result=c("a","b","c","d","e"),area=c("city1","city2")) > barplot(yy,horiz = T,legend=T,col = rainbow(10))

> y1<-data.frame(x1=c(201,100,64,106,154,196,259,294),x2=c(133,72,49,82,126,191,251,338),age=c(1,5,15,25,35,45,55,65))> plot(y1$age,y1$x1,pch=15,col=1,bty="l",ylim = c(0,300), xlab = "age",ylab = "target variable") > lines(y1$age,y1$x1,lwd=2) > axis(side= 1, at=c(0, seq(5, 65, 10)), labels=paste(y1$age, "-"))> points(y1$age, y1$x2, pch=16, col=2) > lines(y1$age, y1$x2, col=2, lwd=2) > legend(0, 300, legend=c("1998", "2003"), col=c(1,2), pch=c(15, 16), lwd=2, bty="n")



您可能也对以下帖子感兴趣

文章有问题?点此查看未经处理的缓存