R语言练习代码是怎样写的
这篇文章给大家介绍R语言练习代码是怎样写的,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。
成都创新互联公司专业为企业提供滴道网站建设、滴道做网站、滴道网站设计、滴道网站制作等企业网站建设、网页设计与制作、滴道企业网站模板建站服务,10余年滴道做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。
x <- c(1:10) x <- c(v1 = 1:4,v2 = 10:14) install.packages() install.packages("xlsx") install.packages("rJava") install.packages("xlsxjars") install.packages("vcd") .libPaths() install.packages(c("AER","ca")) library() library(xlsx) library(rJava) print() require(vcd) require(xlsx) installed.packages() installed.packages()[,1] Rpack <- installed.packages()[,1] save(Rpack,file = "Rpack.Rdata") for (i in Rpack) install.packages(i) help.xlsx() help.start() x <- read.csv("碧彩测试数据1.07",header = TRUE) y <- readClipboard() read.table("clipboard",sep = ",",header = TRUE) read.table("clipboard",sep = "\t",header = TRUE) install.packages("arules") data(Groceries) Groceries a <- c(100,rep(10,4)) mean(a) b <- c(1000,rep(50,9),rep(5,5)) sum(b) A <- c(1,2,5,8,9) jicha <- max(A) - min(A) jicha fangcha <- function(x){return(sum((x-mean(x))^2)/length(x))} fangcha fangcha(A) install.packages("moments") library("moments") data1 x <- read.csv("C:\\Users\\QDM\\Desktop\\销售业绩.csv",header = T) x y <- read.table("C:\\Users\\QDM\\Desktop\\销售业绩.txt",header = T) y z <- read.table("clipboard",header = T,sep = "\t") z 1+3 x <- c(1,3,8,4,7,5,6,1) png(file = "barchart.png") barplot(x) dev.off() x <- read.table("clipboard",header = T,sep = "\t") x x <- read.table("clipboard",header = T) x barplot(apply(x,1,mean)) barplot(apply(x,2,median)) pie(apply(x,2,mean)) barplot(height = 1:10) data <- cbind(a = 1:4, b = 1:4) barplot(data) data <- cbind(a = 1:4, b = 1:4) barplot(data, beside = T) barplot(1:5, width = 5:1) barplot(1:3, space = c(0.1, 0.2, 0.3)) par(mfrow = c(1, 2)) height <- c(1:3) names(height) <- c("A", "B", "C") barplot(height) data <- cbind("A" = 1:4, "B" = 1:4) barplot(data) par(mfrow = c(1, 2)) height <- c(1:3) names(height) <- c("A", "B", "C") barplot(height, names.arg = c("A1", "A2", "A3")) data <- cbind("A" = 1:4, "B" = 1:4) barplot(data, names.arg = c("D", "E")) data <- cbind(a = 1:4, b = 1:4) rownames(data) <- c("A", "B", "C", "D") barplot(data, legend.text = TRUE) data <- cbind(a = 1:4, b = 1:4) rownames(data) <- c("A", "B", "C", "D") barplot(data, legend.text = c("E", "F", "G", "H")) par(mfrow = c(1, 2)) data <- cbind(a = 1:4, b = 1:4) barplot(data, main = "beside = F") barplot(data, beside = T, main = "beside = T") par(mfrow = c(1, 2)) barplot(1:4, main = "horiz = F") barplot(1:4, main = "horiz = T", horiz =T) barplot(1:4, col = "green") barplot(1:4, col = rainbow(4)) barplot(1:4, col = rainbow(4), border = NA, main = "border = NA") par(mfrow = c(1, 3)) barplot(rep(1,4), density = 1, main = "density = 1") barplot(rep(1,4), density = 2, main = "density = 2") barplot(rep(1,4), density = 3, main = "density = 3") par(mfrow = c(1, 3)) barplot(rep(1,4), density = 2, angle = 45, main = "angle = 45") barplot(rep(1,4), density = 2, angle = 90, main = "angle = 90") barplot(rep(1,4), density = 2, angle = 180, main = "angle = 180") par(mfrow = c(1, 2)) data <- cbind(a = 1:4, b = 1:4) barplot(data, axes = F, main = "axes = F") barplot(data, axes = T, main = "axes = T") par(mfrow = c(1, 2)) data <- cbind(a = 1:4, b = 1:4) barplot(data, axisnames = F, main = "axisnames = F") barplot(data, axisnames = T, main = "axisnames = T") par(mfrow = c(1, 3)) data <- cbind(a = 1:4, b = 1:4) barplot(data, offset = 0, main = "offset = 0") barplot(data, offset = 1, main = "offset = 1") barplot(data, offset = 2, main = "offset = 2") barplot(1:4, col = rainbow(4), border = NA, main = "border = NA") barplot(height = 1:7) barplot(height = 1:7,beside = T, main = "2020年5月份业绩") barplot(height = 1:7,beside = T, main = "2020年5月份业绩",col = rainbow(7)) barplot(height = 1:7,beside = T, main = "2020年5月份业绩",col = rainbow(7),border = NA) barplot(height = 1:7,beside = T, main = "2020年5月份业绩",col = rainbow(7),border = NA) QDM <- read.table("clipboard",header = T) QDM QDM <- c(100,200,300,400,500,600) depatment <- c("电商","水产","水果","蔬菜","肉类","综合") barplot(QDM,names.arg = depatment) barplot(QDM,names.arg = depatment,col = "green") barplot(QDM,names.arg = depatment,col = "red") barplot(QDM,names.arg = depatment,col = "blue") barplot(QDM,names.arg = depatment,col = "black") barplot(QDM,names.arg = depatment,col = "pink") barplot(QDM,names.arg = depatment,beside = T, main = "2020年5月份各部门业绩",col = rainbow(7)) barplot(QDM,names.arg = depatment,beside = T, main = "2020年5月份各部门业绩",col = rainbow(7),border = NA) data <- c(60,70,80,90,100) barplot(data) data1 <- c(60,70,80,90,100) bumen <- c("水产","水果","蔬菜","猪肉","综合") barplot(data1,names.arg = bumen) barplot(y,names.arg = x,border = NA,xlab = "部门",ylab = "销售额",main = "2020年5月份各部门总销售额",col = rainbow(4)) barplot(y,names.arg = x,border = "blue",xlab = "部门",ylab = "销售额",main = "2020年5月份各部门总销售额",col = rainbow(4)) x <- c(1020,1640,1340,1610,1942) x y <- c("水产","水果","蔬菜","猪肉","综合") y plot(x,names.arg = y) barplot(x,names.arg = y,border = NA) barplot(x,names.arg = y,border = NA,col = rainbow(5)) plot(x,names.arg = y,type = "b") plot(x,names.arg = y,type = "b",col = "red") plot(x,names.arg = y,type = "b",col = "green") plot(x,names.arg = y,type = "b",col = "DarkTurquoise") n <- 6 pie(x,n) pie(x,y,border = NA) pie(x,y,border = NA,col = rainbow(7)) pie(x,y,col = rainbow(7)) piecolors <- rainbow(n) piecolors pie(x,y,border = "gray",col = rainbow(7)) a <- c(100,150,130,168,111) pie(a,y) x <- c(1,2,3,4,5,6,7) y <- c("周一","周二","周三","周四","周五","周六","周日") barplot(x,names.arg = y) barplot(x,names.arg = y,col = rainbow(7)) barplot(x,names.arg = y,col = rainbow(7),border = NA) pie(x,y) pie(x,y,col = brewer.pal(7,"Set1")) write.table(x,file = "result.txt", sep = "\t", quote = FALSE) x <- read.table("clipboard",header = T,sep = "\t") x y <- read.csv("出入库.csv",header = TRUE) y ls("package:graphics") x <- c(1:4) y <- c(4:6) arrows(x,y) stars(x) box(x) demo(graphics) help(package = "graphics") example("heatmap") example("barplot") example("pie") pie(rep(1, n), labels = "", col = rainbow(n), border = NA, pie+ main = "pie(*, labels=\"\", col=rainbow(n), border=NA,..") pie(c(Sky = 78, "Sunny side of pyramid" = 17, "Shady side of pyramid" = 5), pie+ init.angle = 315, col = c("deepskyblue", "yellow", "yellow3"), border = FALSE) pie> pie(c(Sky = 78, "Sunny side of pyramid" = 17, "Shady side of pyramid" = 5), pie+ init.angle = 315, col = c("deepskyblue", "yellow", "yellow3"), border = FALSE) example("boxplot") women plot(women) barplot(women$height) barplot(women$height,women$weight) plot("fit") methods(plot) methods(print) par() barplot(height = 1:3,col = c("red","green","blue")) barplot(height = 1:3,col = c("red","green","blue"),border = NA) plot(women$height,women$weight) fit <- lm(height ~ weight,data = women) fit summary(fit) install.packages("ggplot2") ?ggplot2 ?barplot install.packages("caret") library("caret") library(caret) data() cars women GermanCredit GermanCredit GermanCredit ?pie x <- c("蔬菜","水果","水产","猪肉","综合") x y <- c(5,4,3,2,1) y pie(y,labels = names(x)) pie(y,labels = names(x),col = rainbow(5)) pie(y,labels = names(x),col = rainbow(5),border = NA) pie(y,labels = names(x),col = rainbow(5),border = NA,edges = 200) pie(y,labels = names(x),col = rainbow(5),border = NA,edges = 10) pie(y,labels = names(x),col = rainbow(5),border = NA,radius = 1) pie(y,labels = names(x),col = rainbow(5),border = NULL,radius = 1) pie(y,labels = names(x),col = rainbow(5),border = "white",radius = 1) pie(y,labels = names(x),col = rainbow(5),border = NULL,radius = 1,main = "滕玉龙") pie(y,labels = names(x),col = rainbow(5),border = NULL,radius = 1, angle = 45) pie(y,labels = names(x),col = rainbow(5),border = NULL,radius = 1, clockwise = TRUE) pie(y,labels = names(x),col = rainbow(5),border = NA,radius = 1, clockwise = TRUE) pie(y,labels = names(x),col = rainbow(5),border = NA,radius = 1, clockwise = TRUE,main = "滕玉龙") example(pie) pie(y,names(x) <- c("蔬菜","水果","水产","猪肉","综合") ,col = rainbow(5),border = NA,radius = 1, clockwise = TRUE,main = "7月份各部门销售占比") library("ggplot2") qplot(Wind,Temp,data = airquality) qplot(Wind,Temp,data = airquality,color = Month) qplot(Wind,Temp,data = airquality,color = I("blue")) qplot(Wind,Temp,data = airquality,shape = Month) qplot(Wind,Temp,data = airquality,size = Month) qplot(Wind,Temp,data = airquality,size = I(15)) qplot(Wind,Temp,data = airquality,size = I(10),color = I("red"),xlab = "风速",ylab = "气温",main = "气温与风速的关系") qplot(Wind,Temp,data = airquality,size = I(10),color = I("red"),xlab = "风速",ylab = "气温",main = "气温与风速的关系",fill = Month) qplot(Wind,data = airquality,fill = Month) qplot(Wind,data = airquality,geom = "density") qplot(Wind,data = airquality,geom = "density",color = Month) qplot(Wind,data = airquality,geom = "dotplot",color = I("green")) df = data.frame(x=1:10, y=seq(1, 20, 2), z=seq(1000, 100, -100), c=paste("color", seq(1, 10, 1))) df install.packages("ggplot2") # 安装包 install.packages("RColorBrewer") library(ggplot2) # 加载包 library(RColorBrewer) ggplot(df, aes(x=x, y=y)) + geom_bar(stat="identity") ggplot(df, aes(x=x, y=y, fill=c)) + geom_bar(stat="identity") + labs(x="x axis", y="y axis", fill="legend") ggplot(df, aes(x=x, y=y, fill=x)) + geom_bar(stat="identity") + labs(x="x axis", y="y axis", fill="legend") ggplot(df, aes(x=x, y=y, fill=z)) + geom_bar(stat="identity") + labs(x="x axis", y="y axis", fill="legend") colors <- colorRampPalette(c("red", "orange"))(10) colors # [1] "#FF0000" "#FF1200" "#FF2400" "#FF3700" "#FF4900" "#FF5B00" "#FF6E00" "#FF8000" "#FF9200" "#FFA500" ggplot(df, aes(x=x, y=y)) + geom_bar(stat="identity", fill=colors[rank(10:1)]) + labs(x="x axis", y="y axis", fill="legend") ggplot(df, aes(x=x, y=y)) + geom_bar(stat="identity", fill=brewer.pal(10, "Set3")) + labs(x="x axis", y="y axis", fill="legend") ?data.frame ?barplot goods <- c("豆芽","茄子","淮山","番茄","芋头","土豆","萝卜","马蹄","莴笋","红薯") goods amount barplot(height = 1:10,col = rainbow(10),border = NA,names.arg = goods,main = "各种农产品的产量(单位:万吨)\n\nMade By 滕玉龙",sub = "左手Python,右手R语言",ylab = "产量(万吨)",xlab = "农产品名称") amount <- c(100, 130, 169, 220, 286, 372, 484, 629, 818, 1063) amount barplot(height = amount,col = rainbow(10),border = NA,names.arg = goods,main = "各种农产品的产量(单位:万吨)\n\nMade By 滕玉龙",sub = "左手Python,右手R语言",ylab = "产量(万吨)",xlab = "农产品名称") grade <- c("大一", "大二", "大三", "大四") amount <- c(15, 38, 123, 35) barplot(height = amount,col = rainbow(4),border = NA,names.arg = grade,main = "各年级发生的频次",sub = "哈佛在等我呢~",ylab = "频次",xlab = "年级")
关于R语言练习代码是怎样写的就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。
当前题目:R语言练习代码是怎样写的
浏览路径:http://scyanting.com/article/pjehpg.html