R语言(R studio)画各类统计图形

分享一下在学习R语言图形绘制的过程,希望可以帮助到大家!(第一次写博客,hhh~)

啥都甭说了,上代码~

1.普通折线图

rm(list = ls())
dose <- c(20,30,40,50,60)
drugA <- c(16,20,27,40,60)
drugB <- c(17,20,30,45,50)
dev.new()
par(mfrow = c(3,3))
#普通折线图
plot(dose,drugA,type = "o",pch = 15,col = "red"
     ,main = "Drug-dose",xlab = "dose",ylab = "response")
lines(dose,drugB,type = "o",pch = 17,col = "blue")
legend("topleft",inset = 0.05,title = "Drug Type",c("A","B")
       ,lty = c(1,1),pch = c(15,17),col = c("red","blue"))

2.条形图

#条形图
##分组条形图
status <- c("poor","improved","excellent","general","worse")
library(vcd)
number <- matrix(c(drugA,drugB),5,2)
name <- c("drugA","drugB")
collist <- c("gray", "gold3", "firebrick", "darkorange3", "tan1")
barplot(number,main = "drugA vs drugB patient status"
        ,xlab = "drug type",ylab = "number", names.arg = name,
       col = collist,beside = TRUE)
##堆砌条形图
barplot(number,main = "drugA vs drugB patient status"
        ,xlab = "drug type",ylab = "number", names.arg = name,
        col = collist)

3.棘状图

number2 <- matrix(c(drugA,drugB),2,5)
spineplot(number2,main = "drugA vs drugB patient status",xaxlabels = name
      ,yaxlabels = status)

R语言还可以画很多图,下篇再见啦~

猜你喜欢

转载自blog.csdn.net/zM356161/article/details/90142437