随笔分类 - R语言
摘要:001、 library(ggplot2) # 构建示例数据 df <- data.frame( lon = c(-3, 2, 5, 7, -8, -9, 1, 0), # 经度 lat = c(40, 42, 48, 50, 36, 35, 43, 45), # 纬度 group = rep(c(
阅读全文
摘要:001、 library(ggplot2) data <- data.frame( x = rnorm(100), y = rnorm(100) ) data$group <- sample(c("A", "B", "C"), 100, replace = TRUE) head(data) ggpl
阅读全文
摘要:001、 library(ggplot2) data <- data.frame( x = rnorm(100), y = rnorm(100) ) ggplot(data, aes(x = x, y = y, color = y)) + geom_point(size = 3) + scale_c
阅读全文
摘要:001、R语言中ggplot绘图去除灰色背景并保留外围框线 library(ggplot2) data <- data.frame( x = rnorm(10), y = rnorm(10) ) ggplot(data, aes(x = x, y = y)) + geom_point() + the
阅读全文
摘要:001、 # 生成随机数据 set.seed(123) # 设置种子以便结果可重复 genes <- paste("Gene", 1:1000) # 基因名称 logFC <- rnorm(1000, mean = 0, sd = 2) # log2 fold change,均值为0,标准差为2的正
阅读全文
摘要:001、方法1 R语言中从向量中删除特定的向量 vec <- c("a", "b", "c", "e", "d") ## 测试向量 remove <- which(vec == "e") ## 获取删除内容的索引值 remove vec[-remove] ## 从原向量中删除 002、方法2 vec
阅读全文
摘要:001、 library(ggplot2) dim(ToothGrowth) head(ToothGrowth) ToothGrowth$dose = as.factor(ToothGrowth$dose) ## 转换为因子 ggplot(ToothGrowth, aes(x=dose, y=len
阅读全文
摘要:001、 library(randomcoloR) palette <- randomColor(count = 54) #随机生成60种颜色,其实里面有重复的 palette <- distinctColorPalette(54) #差异明显的60种 palette plot(1:54, pch
阅读全文
摘要:001、R语言中points 函数 plot(1:5, 1:5, xlim = c(1,6), ylim = c(1,6), type = "n") points(c(3,3), c(2,5), cex = 2, col = "red", pch = 13) 002、 调整大小、颜色 plot(1:
阅读全文
摘要:R语言中数据框中如何实现按照指定列的类别进行排序。 001、 dir() c1 <- rep(c("b","d", "a", "c"), each = 2) c1 c2 <- sample(1:20, 8) c2 dat <- data.frame(c1, c2) ## 生成一个测试数据 idx <
阅读全文
摘要:001、R语言中输出数据框中某一列的字符串长度,并按照字符串的长度进行排序 a <- c("erw", "3s", "errrkk", "r", "r444") b <- letters[1:5] dat <- data.frame(a, b) ## 生成一个测试数据框 dat nchar(dat$
阅读全文
摘要:001、 set.seed(123) group_A <- rnorm(30, mean = 5, sd = 1) # 药物A的效果 group_B <- rnorm(30, mean = 6, sd = 1) # 药物B的效果 u_test_result <- wilcox.test(group_
阅读全文
摘要:001、 df <- data.frame(A = c(1, 2, 3), B = c(4, 5, 6), C = c(7, 8, 9)) row.names(df) <- c("mm", "qq", "dd") df cbind(com1 = rownames(df), df) ## 行号转换为第
阅读全文
摘要:001、 # 创建一个多边形 df <- data.frame( x = c(1, 2, 2, 1, 1.26), y = c(1, 1, 2, 1.6, 1.26) ) df # 绘制多边形 ggplot() + geom_polygon(data = df, aes(x = x, y = y),
阅读全文
摘要:001、frame.plot = T参数绘图 设置是否显示图边框 par(mfrow = c(1,2)) plot(1:10, cex = 3, pch = 19, frame.plot = T, main = "111") ## 显示图边框 plot(1:10, cex = 3, pch = 19
阅读全文
摘要:001、测试01 library(ggplot2) ggplot(data.frame(x = c(1, 3), y = c(1, 3)), aes(x = x, y = y)) + geom_point() + geom_curve(aes(x = 1.5, y = 2.5, xend = 2.6
阅读全文
摘要:001、windows中安装R包,需要编译,调用Rtools报错如下: collect2.exe: error: ld returned 1 exit status no DLL was created ERROR: compilation failed for package 'rgdal' 。
阅读全文
摘要:001、R语言windows中安装R包出现如下报错 Error in system(paste(MAKE, p1(paste("-f", shQuote(makefiles))), "compilers"), : 'make' not found 002、确认是否安装Rtools install.p
阅读全文
摘要:001、R语言read.csv函数发生如下报错: 错误于type.convert.default(data[[i]], as.is = as.is[i], dec = dec, : '<c9>Ϻ<a3>'多字节字符串有错误 002、文件内容 003、 正确做法 > dat2 <- read.csv(
阅读全文
摘要:001、 install.packages("devtools") library("devtools") install_github("lchiffon/REmap")library(REmap) .
阅读全文

浙公网安备 33010602011771号