您好,登錄后才能下訂單哦!
這篇文章給大家介紹R語(yǔ)言練習(xí)代碼是怎樣寫(xiě)的,內(nèi)容非常詳細(xì),感興趣的小伙伴們可以參考借鑒,希望對(duì)大家能有所幫助。
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("碧彩測(cè)試數(shù)據(jù)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\\銷(xiāo)售業(yè)績(jī).csv",header = T) x y <- read.table("C:\\Users\\QDM\\Desktop\\銷(xiāo)售業(yè)績(jī).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月份業(yè)績(jī)") barplot(height = 1:7,beside = T, main = "2020年5月份業(yè)績(jī)",col = rainbow(7)) barplot(height = 1:7,beside = T, main = "2020年5月份業(yè)績(jī)",col = rainbow(7),border = NA) barplot(height = 1:7,beside = T, main = "2020年5月份業(yè)績(jī)",col = rainbow(7),border = NA) QDM <- read.table("clipboard",header = T) QDM QDM <- c(100,200,300,400,500,600) depatment <- c("電商","水產(chǎn)","水果","蔬菜","肉類(lèi)","綜合") 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月份各部門(mén)業(yè)績(jī)",col = rainbow(7)) barplot(QDM,names.arg = depatment,beside = T, main = "2020年5月份各部門(mén)業(yè)績(jī)",col = rainbow(7),border = NA) data <- c(60,70,80,90,100) barplot(data) data1 <- c(60,70,80,90,100) bumen <- c("水產(chǎn)","水果","蔬菜","豬肉","綜合") barplot(data1,names.arg = bumen) barplot(y,names.arg = x,border = NA,xlab = "部門(mén)",ylab = "銷(xiāo)售額",main = "2020年5月份各部門(mén)總銷(xiāo)售額",col = rainbow(4)) barplot(y,names.arg = x,border = "blue",xlab = "部門(mén)",ylab = "銷(xiāo)售額",main = "2020年5月份各部門(mén)總銷(xiāo)售額",col = rainbow(4)) x <- c(1020,1640,1340,1610,1942) x y <- c("水產(chǎn)","水果","蔬菜","豬肉","綜合") 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("出入庫(kù).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("蔬菜","水果","水產(chǎn)","豬肉","綜合") 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("蔬菜","水果","水產(chǎn)","豬肉","綜合") ,col = rainbow(5),border = NA,radius = 1, clockwise = TRUE,main = "7月份各部門(mén)銷(xiāo)售占比") 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 = "風(fēng)速",ylab = "氣溫",main = "氣溫與風(fēng)速的關(guān)系") qplot(Wind,Temp,data = airquality,size = I(10),color = I("red"),xlab = "風(fēng)速",ylab = "氣溫",main = "氣溫與風(fēng)速的關(guān)系",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óng)產(chǎn)品的產(chǎn)量(單位:萬(wàn)噸)\n\nMade By 滕玉龍",sub = "左手Python,右手R語(yǔ)言",ylab = "產(chǎn)量(萬(wàn)噸)",xlab = "農(nóng)產(chǎn)品名稱(chēng)") 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óng)產(chǎn)品的產(chǎn)量(單位:萬(wàn)噸)\n\nMade By 滕玉龍",sub = "左手Python,右手R語(yǔ)言",ylab = "產(chǎn)量(萬(wàn)噸)",xlab = "農(nóng)產(chǎn)品名稱(chēng)") grade <- c("大一", "大二", "大三", "大四") amount <- c(15, 38, 123, 35) barplot(height = amount,col = rainbow(4),border = NA,names.arg = grade,main = "各年級(jí)發(fā)生的頻次",sub = "哈佛在等我呢~",ylab = "頻次",xlab = "年級(jí)")
關(guān)于R語(yǔ)言練習(xí)代碼是怎樣寫(xiě)的就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺(jué)得文章不錯(cuò),可以把它分享出去讓更多的人看到。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。