背景介绍
今天有一位网友问,下面这张图如何做?仔细一看,其实就是三张柱状图,将需要的数值映射到颜色上即可!
2024年09月12日
Functions break large computing tasks into smaller ones, and enable people to build on what others have done instead of starting over from scratch. Appropriate functions hide details of operation from parts of the program that don't need to know about them, thus clarifying the whole, and easing the pain of making changes.
2024年09月12日
【个数可变的位置参数】
1)自定义函数时,可能无法事先确定传递的位置实参的个数时(需要根据实际情况来),
这种情况就需要使用可变的位置参数。
(2)使用 * 定义个数可变的位置形参
3)返回值结果为一个元组
2024年09月12日
在每节,先运行以下这几行程序。
library(ggplot2)
library(ggpubr)
library(ggtext) #用于个性化图表
library(dplyr) #用于数据处理
p_base <- ggplot(data = mtcars, aes(x = wt, y = mpg)) + geom_point()
2024年09月12日
主要数据预处理扩展函数介绍。
关注二幺幺统计课堂公众号可以加入学术交流,群免费获得各种数据资源。大家好,我们已经学习了数据预处理中的数据清洗,数据规划,除了以上操作的一些函数以外,而还提供了很多其他的一些函数。本小节将扩展介绍一些其他的统计函数,我这里主要列举了五个。
·第一个lm是做线性回归的,它是利用因变量与自变量去建立线性回归模型这样的计算。
2024年09月12日
R是用于统计分析、绘图的语言和操作环境。这里介绍如何使用R语言的ggplot2扩展包生成图形。
我们首先使用R语言的pressure数据集和qlpot()函数来个简单的例子:
> library(ggplot2)
> qplot(temperature,pressure,data = pressure)
再使用qplot()来一个稍微复杂一点的图形
2024年09月12日
饼图显示一个数据系列中各项的大小与各项总和的比例。也就是说我们想直观的看某一样本值在所有样本总值中所占的比例时,可以使用饼图来表示。
在R语言中绘制饼图的函数为pie,其使用格式如下:
pie(x, labels = names(x), edges = 200, radius = 0.8, clockwise = FALSE, init.angle = if(clockwise) 90 else 0, density = NULL, angle = 45, col = NULL, border = NULL, lty = NULL, main = NULL, ...)
2024年09月12日
本函数主要用于计算otu丰度表的a多样性计算
#依赖包
library(vegan)
library(picante)
计算函数
alpha_diversity <- function(x, tree = NULL) {
observed_species <- estimateR(x)[1, ]
Chao1 <- estimateR(x)[2, ]
ACE <- estimateR(x)[4, ]
Shannon <- diversity(x, index = 'shannon',base = 2)
Simpson <- diversity(x, index = 'simpson') #注意,这里是Gini-Simpson 指数
goods_Coverage <- 1 - rowSums(x == 1) / rowSums(x)
#保留四位小数
Shannon <- sprintf("%0.4f", Shannon)
Simpson <- sprintf("%0.4f", Simpson)
goods_Coverage <- sprintf("%0.4f", goods_Coverage)
result <- data.frame(observed_species, ACE,Chao1, Shannon, Simpson, goods_Coverage)
if (!is.null(tree)) {
PD_whole_tree <- pd(x, tree, include.root = FALSE)[1]
names(PD_whole_tree) <- 'PD_whole_tree'
result <- cbind(result, PD_whole_tree)
result <- data.frame(observed_species, ACE,Chao1, Shannon, Simpson,
PD_whole_tree ,goods_Coverage)
}
result
}
2024年09月12日
在每节,先运行以下这几行程序。
library(ggplot2)
library(ggpubr)
library(ggtext) #用于个性化图表
library(dplyr) #用于数据处理
p_base <- ggplot(data = mtcars, aes(x = wt, y = mpg)) + geom_point()
2024年09月12日
基本上,几乎每一个初学者在刚接触C语言时,都会被告知C语言程序的默认入口是 main() 函数,程序总是从入口函数处开始运行。一般来说,main() 函数有两个常用的原型,它们的C语言代码是下面这样的:
int main(); int main(int argc, char *argv[]);