R语言绘制PCA双标图、碎石图、变量载荷图和变量贡献图

1、原论文数据双标图

代码:

setwd("D:/Desktop/0000/R") #更改路径#导入数据
df <- read.table("Input data.csv", header = T, sep = ",")# -----------------------------------
#所需的包:
packages <- c("ggplot2", "tidyr", "dplyr", "readr", "ggrepel", "cowplot", "factoextra")
#安装你尚未安装的R包
installed_packages <- packages %in% rownames(installed.packages())
if (any(installed_packages == FALSE)) {install.packages(packages[!installed_packages])
}
invisible(lapply(packages, library, character.only = TRUE))# -----------------------------------
# 设置一些颜色、文字的基础设置
# Colors:
CatCol <- c(CSH = "#586158", DBF = "#C46B39", EBF = "#4DD8C0", ENF = "#3885AB", GRA = "#9C4DC4",MF = "#C4AA4D", OSH = "#443396", SAV = "#CC99CC", WET = "#88C44D", WSA = "#AB3232"
)
Three_colorblind <- c("#A8AD6F", "#AD6FA8", "#6FA8AD") #c("#809844", "#4f85b0", "#b07495")
graph_elements_dark <- "black"
plot_elements_light <- "gray75"
plot_elements_dark <- "gray25"# Transparency:
boot_alpha_main <- 0.9
boot_alpha_small <- 0.05# Text:
# if (n_pcs > 3) {x_angle <- 270; x_adjust <- 0.25} else {x_angle <- 0; x_adjust <- 0} # option to change orientation of x axis text
x_angle <- 0; x_adjust <- 0
title_text <- 9 # Nature Communications: max 7 pt; cowplot multiplier: 1/1.618; 7 pt : 1/1.618 = x pt : 1; x = 7 / 1/1.618; x = 11.326 (round up to integer)
subtitle_text <- 9
normal_text <- 9 # Nature Communications: min 5 pt; cowplot multiplier: 1/1.618; 5 pt : 1/1.618 = x pt : 1; x = 5 / 1/1.618; x = 8.09 (round up to integer)# Element dimensions:
plot_linewidth <- 0.33
point_shape <- 18
point_size <- 1.5# Initialize figure lists:
p_biplot <- list(); p_r2 <- list(); p_load <- list(); p_contr <- list(); col_ii <- list()# Labels:
veg_sub_labels <- c("All Sites", "All Forests", "Evergreen Needle-Forests") # -----------------------------------
#选择PCA所需的数据
codes_4_PCA <- c("SITE_ID", "IGBP", "GPPsat", "wLL", "wNmass", "wLMA", "RECOmax") # 选择需要的列数据
#执行筛选
df_subset <- df %>%dplyr::select(all_of(codes_4_PCA))
#运行PCA。dplyr::select(-species):将不需要的列数据去除
pca_result <- FactoMineR::PCA(df_subset %>% dplyr::select(-SITE_ID, -IGBP), scale.unit = T, ncp = 10, graph = F)# -----------------------------------
#绘图
p1<- fviz_pca_biplot(pca_result,axes = c(1, 2),col.ind = df_subset$IGBP, #"grey50",# col.ind = NA, #plot_elements_light, #"white",geom.ind = "point",palette = CatCol,#'futurama',label = "var",col.var = plot_elements_dark,labelsize = 3,repel = TRUE,pointshape = 16,pointsize = 2,alpha.ind = 0.67,arrowsize = 0.5)# -----------------------------------
# 它是ggplot2对象,我们在此基础上进一步修改一下标注。
p1<-p1+labs(title = "",x = "PC1",y = "PC2",fill = "IGBP") +guides(fill = guide_legend(title = "")) +theme(title = element_blank(),text = element_text(size = normal_text),axis.line = element_blank(),axis.ticks = element_blank(),axis.title = element_text(size = title_text, face = "bold"),axis.text = element_text(size = normal_text),#plot.margin = unit(c(0, 0, 0, 0), "cm"),# legend.position = "none"legend.text = element_text(size = subtitle_text),legend.key.height = unit(5, "mm"),legend.key.width = unit(2, "mm"))
p1

参考:Leaf-level coordination principles propagate to the ecosystem scale (https://doi.org/10.1038/s41467-023-39572-5)、主成分分析图。

2、我选用iris数据进行重新绘制测试双标图

代码:

setwd("D:/Desktop/0000/R") #更改路径#导入数据
df <- read.table("iris1.csv", header = T, sep = ",")# -----------------------------------
#所需的包:
packages <- c("ggplot2", "tidyr", "dplyr", "readr", "ggrepel", "cowplot", "factoextra")
#安装你尚未安装的R包
installed_packages <- packages %in% rownames(installed.packages())
if (any(installed_packages == FALSE)) {install.packages(packages[!installed_packages])
}
invisible(lapply(packages, library, character.only = TRUE))# -----------------------------------
# 设置一些颜色、文字的基础设置
# Colors:
CatCol <- c(setosa = "#586158", versicolor = "#C46B39", virginica = "#4DD8C0") # 设置类别颜色
Three_colorblind <- c("#A8AD6F", "#AD6FA8", "#6FA8AD") #c("#809844", "#4f85b0", "#b07495")
graph_elements_dark <- "black"
plot_elements_light <- "gray75"
plot_elements_dark <- "gray25"# Transparency:
boot_alpha_main <- 0.9
boot_alpha_small <- 0.05# Text:
# if (n_pcs > 3) {x_angle <- 270; x_adjust <- 0.25} else {x_angle <- 0; x_adjust <- 0} # option to change orientation of x axis text
x_angle <- 0; x_adjust <- 0
title_text <- 9 # Nature Communications: max 7 pt; cowplot multiplier: 1/1.618; 7 pt : 1/1.618 = x pt : 1; x = 7 / 1/1.618; x = 11.326 (round up to integer)
subtitle_text <- 9
normal_text <- 9 # Nature Communications: min 5 pt; cowplot multiplier: 1/1.618; 5 pt : 1/1.618 = x pt : 1; x = 5 / 1/1.618; x = 8.09 (round up to integer)# Element dimensions:
plot_linewidth <- 0.33
point_shape <- 18
point_size <- 1.5# Initialize figure lists:
p_biplot <- list(); p_r2 <- list(); p_load <- list(); p_contr <- list(); col_ii <- list()# Labels:
veg_sub_labels <- c("All Sites", "All Forests", "Evergreen Needle-Forests") # -----------------------------------
#选择PCA所需的数据
codes_4_PCA <- c("sepal_length", "sepal_width", "petal_length", "petal_width", "species") # 选择需要的列数据
#执行筛选
df_subset <- df %>%dplyr::select(all_of(codes_4_PCA))
#运行PCA。dplyr::select(-species):将不需要的列数据去除
pca_result <- FactoMineR::PCA(df_subset %>% dplyr::select(-species), scale.unit = T, ncp = 10, graph = F)# -----------------------------------
#绘图
p1<- fviz_pca_biplot(pca_result,axes = c(1, 2),col.ind = df_subset$species, #"grey50",# col.ind = NA, #plot_elements_light, #"white",geom.ind = "point",palette = CatCol,#'futurama',label = "var",col.var = plot_elements_dark,labelsize = 3,repel = TRUE,pointshape = 16,pointsize = 2,alpha.ind = 0.67,arrowsize = 0.5)# -----------------------------------
# 它是ggplot2对象,我们在此基础上修改一下标注。
p1<-p1+labs(title = "",x = "PC1",y = "PC2",fill = "IGBP") +guides(fill = guide_legend(title = "")) +theme(title = element_blank(),text = element_text(size = normal_text),axis.line = element_blank(),axis.ticks = element_blank(),axis.title = element_text(size = title_text, face = "bold"),axis.text = element_text(size = normal_text),#plot.margin = unit(c(0, 0, 0, 0), "cm"),# legend.position = "none"legend.text = element_text(size = subtitle_text),legend.key.height = unit(5, "mm"),legend.key.width = unit(2, "mm"))
p1

3、iris数据进行绘制碎石图、变量载荷图、变量贡献图

代码:

#加载包
library(dplyr) #用于数据预处理
library(tidyr) #用于数据预处理
library(stringr) #用于字符串处理
library(modelr) #用于自助法重抽样
library(FactoMineR) #用于PCA
library(ade4) #用于PCA
library(factoextra) #用于PCA结果提取及绘图
#所需的包:
packages <- c("ggplot2", "tidyr", "dplyr", "readr", "ggrepel", "cowplot", "factoextra")
#安装你尚未安装的R包
installed_packages <- packages %in% rownames(installed.packages())
if (any(installed_packages == FALSE)) {install.packages(packages[!installed_packages])
}
invisible(lapply(packages, library, character.only = TRUE))setwd("D:/Desktop/0000/R") #更改路径
# 加载数据
df <- read.csv("iris.csv",header = T, row.names = 1) # row.names = 1: 第一列为标签,这时赋值给df时就没有这列了#重抽样
set.seed(123) #设置随机种子
tt=99 #设置重抽样的次数。iris[,-5]:表示去除第5列,因为这是类别
df_boot <- iris[,-5] %>% modelr::bootstrap(n = tt) #重抽样,结果是一个列表,包含499个数据框#使用循环对每一个数据集进行PCA
#初始化3个空变量
N_PCS <- tibble() #使用维数检验保留的PC数量
pca_stats <- tibble() #变量的贡献和载荷
R2 <- c() #解释方差占比#使用循环对每一个数据集进行PCA
#初始化3个空变量
N_PCS <- tibble() #使用维数检验保留的PC数量
pca_stats <- tibble() #变量的贡献和载荷
R2 <- c() #解释方差占比#循环
for (j in 1:tt) {##提取第j次bootstrap的数据dat <- df_boot %>% slice(j) %>% # 选择第j行pull(strap) %>% # 提取列表as.data.frame() # 提取数据集#使用FactoMineR包执行PCApca_result <- FactoMineR::PCA(dat, scale.unit = T, ncp = 4, graph = F) # ncp = 4:降维几个主成分,设置最大即为全部#使用ade4包执行PCA# center:指定是否对数据进行中心化,默认为 TRUE。中心化意味着将数据减去各自的均值,使得数据在每个维度上的平均值为零。# scale:指定是否对数据进行缩放,默认为 TRUE。缩放意味着将数据除以各自的标准差,使得数据在每个维度上的标准差为一。# scannf:指定是否计算特征值和特征向量,默认为 FALSE。如果设置为 TRUE,则会计算特征值和特征向量。pca1 <- ade4::dudi.pca(dat, center = TRUE, scale = TRUE, scannf = FALSE, nf = 4) # nf= 4:降维几个主成分,设置最大即为全部#检测不确定性和显著性#执行维数检验pc_tested <-testdim(pca1, nrepet = 999)###提取bootstrap数据集的PCA结果N_PCS <- N_PCS %>% bind_rows(tibble(strap = j, n_pcs = pc_tested$nb.cor)) #第j次运行的PCApca_stats <- bind_rows(pca_stats,pca_result$var$contrib %>% # add contributionsas_tibble(rownames = "var") %>%pivot_longer(cols = !var, names_to = "PC", values_to = "contrib") %>% left_join(pca_result$var$coord %>% # add loadingsas_tibble(rownames = "var") %>%pivot_longer(cols = !var, names_to = "PC", values_to = "loading"),by = c("var", "PC")) %>% mutate(PC = str_sub(PC, start = 5), #提取PC名称中的数字strap = j) # bootstrap run number) #得到变量贡献和载荷R2 <- bind_rows(R2,tibble(PC = pca_result[["eig"]]%>% rownames(),exp_var = pca_result[["eig"]][,2],strap = j) %>% mutate(PC = str_sub(PC, start = 6)) #提取PC名称中的数字)
}#保留的PC数量
N_PCS <- N_PCS %>%group_by(n_pcs) %>% summarise(n_rep = n()) %>% #对重复值进行计数mutate(retained = n_rep / tt * 100) #计算运行次数百分比
pc_ret <- N_PCS %>% filter(retained == max(retained))
#输出结果的摘要
print(paste0("Number of statistical significant components according to Dray method (Dray et al., 2008) was ",pc_ret[1,1], " in ", round(pc_ret[1,3], digits = 1), "% of runs."))n_pcs <- NA #保留PC数的初始设置
# n_pcs <- 2 #可以手动设置保留PC数
if (is.na(n_pcs)) {n_pcs <- N_PCS %>% filter(retained == max(retained)) %>% select(n_pcs) %>% unlist() %>% unname()
} #按照Dray等人的方法设置保留PC数##变量贡献和载荷
pca_stats <- pca_stats %>% group_by(PC, var) %>% mutate(contrib_mean = mean(contrib),contrib_median = median(contrib),contrib_std = sd(contrib),# contrib_q25 = quantile(contrib, 0.25), contrib_q75 = quantile(contrib, 0.75),loading_mean = mean(loading),loading_median = median(loading),loading_std = sd(loading),# loading_q25 = quantile(loading, 0.25), loading_q75 = quantile(loading, 0.75)) %>% ungroup() %>% dplyr::rename(contrib_boot = contrib, loading_boot = loading) #重命名以免后续的匹配过程出现混乱##修改PC名称
pca_stats <- pca_stats %>%mutate(PC_name = paste0("PC", PC))##解释方差占比
R2 <- R2 %>% group_by(PC) %>% mutate(R2_mean = mean(exp_var),R2_median = median(exp_var),R2_std = sd(exp_var),# R2_q25 = quantile(exp_var, 0.25), R2_q75 = quantile(exp_var, 0.75)) %>% ungroup() %>% dplyr::rename(R2_boot = exp_var) #重命名以免后续的匹配过程出现混乱##添加到pca_stats的表格中
pca_stats <- pca_stats %>% left_join(R2, by = c("PC", "strap"))#对原始数据的PCA
pca_result <- FactoMineR::PCA(iris[,-5], scale.unit = T, ncp = 4, graph = F)#添加原始数据计算得到的实际值
pca_stats <- pca_stats %>% dplyr::left_join( #添加原始数据的R2(不是bootstrapping的均值)tibble(PC = pca_result[["eig"]] %>% rownames(),R2 = pca_result[["eig"]][,2]) %>% mutate(PC = str_sub(PC, start = 6)), #提取PC数by = "PC") %>% dplyr::left_join( #添加原始数据的变量贡献(不是bootstrapping的均值)pca_result$var$contrib %>% #添加贡献as_tibble(rownames = "var") %>%pivot_longer(cols = !var, names_to = "PC", values_to = "contrib") %>% mutate(PC = str_sub(PC, start = 5)), #提取PC数by = c("PC", "var")) %>%dplyr::left_join( #添加原始数据的变量载荷(不是bootstrapping的均值)pca_result$var$coord %>% #添加载荷as_tibble(rownames = "var") %>%pivot_longer(cols = !var, names_to = "PC", values_to = "loading") %>% mutate(PC = str_sub(PC, start = 5)), # extract PC numbersby = c("PC", "var"))## 添加PC数的保留百分比(在自助法中PC被保留得有多频繁)
pca_stats <- pca_stats %>% dplyr::left_join(N_PCS %>% dplyr::mutate(PC = n_pcs %>% as.character) %>% dplyr::select(PC, retained),by = "PC") # -----------------------------------
# 绘制图碎石图
dat_boot <- pca_stats %>%dplyr::select(PC_name, PC, R2_boot) %>% unique()%>% #去除重复dplyr::mutate(PC = as.character(PC))dat_true <- pca_stats %>%dplyr::select(PC_name, PC, R2, R2_median, R2_std) %>% unique() %>% #去除重复dplyr::mutate(PC = as.character(PC))p2 <- ggplot(data = dat_true, aes(x = PC_name, y = R2, group = 1)) + # x = PC -> only numbers on axis, x = PC_name -> can give problems with PC10 being ordered before PC2;# group 1 是用来避免某些warning/error的geom_errorbar(aes(ymin = R2 - R2_std, ymax = R2 + R2_std),color = Three_colorblind[1], linewidth = plot_linewidth, width = 0.4) + # bootstrapping的标准差# geom_bar(stat = "identity", position = position_dodge(), fill = Three_colorblind[1], width = 0.61) + #b07a4f, #9c6a5e, #643c3cgeom_line(color = Three_colorblind[1]) +geom_point(color = Three_colorblind[1], size = point_size) + #实际值geom_jitter(data = dat_boot, aes(x = PC_name, y = R2_boot, group = 1), alpha = 0.1,color = "black", shape = point_shape, size = 0.5, width = 0.1) + #每次自助样本的值geom_point(aes(x = PC_name, y = R2_median), color = plot_elements_dark,alpha = boot_alpha_main, shape = point_shape, size = point_size) + #添加自助法得到的中位数值geom_text(aes(x = PC_name, y = R2 + R2_std + 2, label = paste0(R2 %>% round(digits = 1), "%")),nudge_x = 0.33, size = 2) + #添加数值标注labs(title = "", x = "", y = "Explained variance") +theme_classic() +theme(title = element_blank(),text = element_text(size = normal_text),axis.line = element_line(color = graph_elements_dark),axis.ticks.x = element_line(color = graph_elements_dark),axis.ticks.y = element_blank(),axis.title = element_text(size = title_text, face = "bold"),# axis.title.x = element_blank(), #已经在'labs'中指定axis.text = element_text(size = normal_text),axis.text.y = element_blank(),plot.margin = unit(c(0, 1, 0, 1), "cm"),legend.position = "none") +NULL
p2# -----------------------------------
# 绘制变量载荷图
dat_boot <- pca_stats %>%dplyr::filter(PC <= n_pcs[1]) %>% #去除额外的PCdplyr::select(PC_name, var, loading_boot) %>% unique() #去除重复dat_true <- pca_stats %>%dplyr::filter(PC <= n_pcs[1]) %>% #去除额外的PCdplyr::select(PC_name, var, loading, loading_median, loading_std) %>% unique() #去除重复p3 <- ggplot(data = dat_true, aes(x = var, y = loading)) +facet_grid(. ~ PC_name, scales = "free_y") +geom_errorbar(aes(ymin = loading - loading_std, ymax = loading + loading_std), # loading_q25, ymax = loading_q75color = Three_colorblind[2], linewidth = plot_linewidth, width = 0.9) + # standard error = std from bootstrappinggeom_bar(stat = "identity", position = position_dodge(), fill = Three_colorblind[2]) + #b07a4f, #9c6a5e, #643c3cgeom_hline(yintercept = 0, color = graph_elements_dark) +geom_jitter(data = dat_boot, aes(x = var, y = loading_boot), alpha = boot_alpha_small, color = plot_elements_dark,shape = point_shape, size = 0.2, width = 0.1) + #每次自助抽样的值geom_point(aes(x = var, y = loading_median), alpha = boot_alpha_main, shape = point_shape,size = point_size, color = plot_elements_dark) + #添加自助法得到的中位数值coord_flip() +  #对调坐标轴以更好地展示图形scale_y_continuous(breaks = waiver(), n.breaks = 4) + #修改x轴(对调后,这就是y轴)labs(y = "Loadings", x = "", title = "") +theme_classic() +theme(title = element_text(size = normal_text, face = "bold"),text = element_text(size = normal_text),axis.line.x = element_line(color = graph_elements_dark),axis.line.y = element_blank(),axis.ticks.x = element_line(color = graph_elements_dark),axis.ticks.y = element_blank(),axis.title = element_text(size = title_text),axis.text = element_text(size = normal_text),axis.text.x = element_text(angle = x_angle, vjust = x_adjust),legend.position = "none",legend.title = element_text(size = title_text),legend.text = element_text(size = subtitle_text),legend.key.height = unit(1.0, "mm"),legend.key.width = unit(1.0, "mm"),plot.margin = unit(c(0, 0, 0, 0), "cm"),strip.text = element_text(face = "bold", size = title_text),strip.background = element_blank()) +NULL
p3# -----------------------------------
# 绘制变量贡献图
dat_boot <- pca_stats %>%dplyr::filter(PC <= n_pcs[1]) %>% #去除额外的PCdplyr::select(PC_name, var, contrib_boot) %>% unique() #去除重复dat_true <- pca_stats %>%dplyr::filter(PC <= n_pcs[1]) %>% # remove additional PCsdplyr::select(PC_name, var, contrib, contrib_median, contrib_std) %>% unique() #去除重复p4<- ggplot(data = dat_true, aes(x = var, y = contrib)) +facet_grid(. ~ PC_name, scales = "free_y") +geom_errorbar(aes(ymin = contrib_median - contrib_std, ymax = contrib_median + contrib_std), # ymin = contrib_q25, ymax = contrib_q75color = Three_colorblind[3], linewidth = plot_linewidth, width = 0.9) + # standard error = standard deviation from bootstrappinggeom_bar(stat = "identity", position = position_dodge(), fill = Three_colorblind[3]) + #4f85b0, #59918e, #3c6464geom_hline(yintercept = 0, color = graph_elements_dark) +geom_jitter(data = dat_boot, aes(x = var, y = contrib_boot), alpha = boot_alpha_small, color = plot_elements_dark,shape = point_shape, size = 0.2, width = 0.1) + #每次自助抽样的值geom_point(aes(x = var, y = contrib_median), alpha = boot_alpha_main, shape = point_shape,size = point_size, color = plot_elements_dark) + #添加自助法得到的中位数值coord_flip() + #对调坐标轴以更好地展示图形scale_y_continuous(breaks = waiver(), n.breaks = 4) + #添加自助法得到的中位数值labs(y = "Contribution [%]", x = "", title = "") +theme_classic() +theme(title = element_text(size = normal_text, face = "bold"),text = element_text(size = normal_text),axis.line.x = element_line(color = graph_elements_dark),axis.line.y = element_blank(),axis.ticks.x = element_line(color = graph_elements_dark),axis.ticks.y = element_blank(),axis.title = element_text(size = title_text),axis.text = element_text(size = normal_text),axis.text.x = element_text(angle = x_angle, vjust = x_adjust),legend.position = "none",legend.title = element_text(size = title_text),legend.text = element_text(size = subtitle_text),legend.key.height = unit(1.0, "mm"),legend.key.width = unit(1.0, "mm"),# plot.margin = unit(c(0, 0, 0, 0), "cm"),strip.text = element_text(face = "bold", size = title_text),strip.background = element_blank()) +NULL
p4# -----------------------------------
# 拼图
library(patchwork)
p2+p3/p4

文中用到的数据代码:R语言绘制 PCA 双标图、碎石图、变量载荷图和变量贡献图(self).zip - 蓝奏云

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/86470.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Centos下安装 oracle11g 博客2

[oraclewangmengyuan database]$ ./runInstaller -silent -responseFile /home/oracle/database/response/db_install.rsp -ignorePrereq ./runInstaller -silent -responseFile /home/oracle/database/response/db_install.rsp -ignorePrereq 正在启动 Oracle Universal Insta…

Innodb 原理和日志

一、MySQL结构 客户端 server层 查询缓存&#xff08;5.7&#xff09; 连接器 分析器 优化器 执行器 引擎层 二、一条update操作mysql的流程 三、MySQL的日志 &#xff08;1&#xff09;redo log 保证MySQL 持久性的关键&#xff0c;如果MySQL宕机&#xff0c;buffer pool…

Java编程的精髓:深入理解JVM和性能优化

文章目录 Java虚拟机&#xff08;JVM&#xff09;的核心概念1. 类加载器&#xff08;Class Loader&#xff09;2. 内存区域3. 垃圾回收&#xff08;Garbage Collection&#xff09;4. 类型转换和多态 JVM性能调优1. JVM参数调整2. 内存管理3. 多线程优化4. 使用性能分析工具5. …

【【萌新的FPGA学习之按键控制LED实验】】

按键控制LED实验 在写这篇文章之前我必须对我的错误表示深刻的道歉 因为我之前的文章自己也是边看边学给大家带来了大的困扰 抱歉抱歉 我们这里讲述一下综合和仿真的关系 其实我们更多的是应该关注仿真下得到的波形情况 然后分析 对于综合&#xff0c;综合的最大的目的还是看功…

python+opencv寻找图片或视频中颜色进行追踪之HSV颜色处理

pythonopencv寻找图片或视频中颜色进行追踪之HSV颜色处理 1.颜色空间转换 import cv2img cv2.imread(1.jpg) # 转换为灰度图 img_gray cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)cv2.imshow(img, img) cv2.imshow(gray, img_gray) cv2.waitKey(0)cv2.cvtColor()用来进行颜色模…

uniapp项目实践总结(十九)版本更新和热更新实现方法

导语:当一个 APP 应用开发完成以后,就要上架应用商店,但有时候修改一些小问题或者推出一些活动,又不想频繁地提交应用商店审核,那么就可以使用应用内更新功能来进行应用的版本升级更新或热更新,下面就介绍一下实现的方法。 目录 准备工作原理分析实战演练案例展示准备工作…

打印大对象日志导致GC问题的解决

内容&#xff1a; rpc调用外部服务时&#xff0c;需要将req和resp的信息打印出来&#xff0c;以便于排查问题。但是有的rpc服务的resp信息过于庞大&#xff0c;比如resp中有List<>信息&#xff0c;list很大很大时会导致log.info打印信息时&#xff0c;产生GC&#xff0c…

国足亚运会4:0战胜缅甸

9月21日晚&#xff0c;中国男足亚运队以4:0战胜小组赛对手缅甸队&#xff0c;谭龙5分钟打入两球&#xff0c;王振澳、戴伟浚各进一球。 这是继9月19日5:1战胜印度队后&#xff0c;中国队取得的第二场胜利。 目前&#xff0c;国足亚运队已提前锁定淘汰赛资格&#xff0c;球队最后…

leetcode:2446. 判断两个事件是否存在冲突(python3解法)

难度&#xff1a;简单 给你两个字符串数组 event1 和 event2 &#xff0c;表示发生在同一天的两个闭区间时间段事件&#xff0c;其中&#xff1a; event1 [startTime1, endTime1] 且event2 [startTime2, endTime2] 事件的时间为有效的 24 小时制且按 HH:MM 格式给出。 当两个…

网站接入公网并配置域名访问【详细教程】

网站接入公网并配置域名访问【详细教程】 安装Nginx上传网页文件配置Nginx腾讯云配置域名映射接入公网备案流程 本教程将以腾讯云服务器和腾讯云域名为例&#xff0c;介绍如何快速将网站接入公网并配置域名访问。我们将使用xshell工具进行操作&#xff0c;并涵盖安装nginx、上传…

Python项目Flask ipv6双栈支持改造

一、背景 Flask 是一个微型的(轻量)使用Python 语言开发的 WSGI Web 框架(一组库和模块),基于Werkzeug WSGI工具箱/库和Jinja2 模板引擎,当然,Python的WEB框架还有:Django、Tornado、Webpy,这暂且不提。 Flask使用BSD授权。 Flask也被称为microframework(微框架),F…

Windows安装Docker Desktop并配置镜像、修改内存占用大小

启用Hyper-V Win S 搜索控制面板 安装WSL2 第一种方法&#xff08;推荐&#xff09; 以管理员运行命令提示符&#xff0c;然后重启Docker Desktop wsl --updatewsl --set-default-version 2第2种方法去微软官网下载WSL2并安装 《微软官网下载WSL2》 配置WSL2最大内…

Linux三大搜索指令的区别

find&#xff1a;可以在指定的路径下进行文件的搜索 —— 真的在磁盘文件中查找 例如find /usr/bin/ -name ls which 可以在指令路径下&#xff0c;/usr/bin,搜索指令文件 例如&#xff1a;which ls whereis:在系统特定的路径下查找&#xff0c;既可以找到可执行程序&#xff…

安装k8s集群

一、前置环境配置 安装两台centos 实验环境&#xff0c;一台pc配有docker环境&#xff0c;有两个centsos7容器&#xff0c;其中一个容器作为master&#xff0c;一个作为node。如果master与node都是用默认端口&#xff0c;会存在冲突&#xff0c;所以在此基础上做细微的调整。…

Kafka的消息传递保证和一致性

前言 通过前面的文章&#xff0c;相信大家对Kafka有了一定的了解了&#xff0c;那接下来问题就来了&#xff0c;Kafka既然作为一个分布式的消息队列系统&#xff0c;那它会不会出现消息丢失或者重复消费的情况呢&#xff1f;今天咱们就来一探。 实现机制 Kafka采用了一系列机…

pycharm 中package, directory, sources root, resources root的区别

【遇到的问题】 导入yolov5中有utils文件&#xff0c;自己的代码中也有utils文件&#xff0c;使得yolov5中的这部分引用出错了。 【解决方案】 单独建立detection文件夹&#xff0c;把检测相关的都放在这里&#xff0c;yolov5是github上拉取的源码&#xff0c;发现yolov5中fr…

sum = sum * 10 + ch - ‘0‘;的含义

scanf中以%c格式获取的是单个字符[1]&#xff0c;实际存储的是该字符对应的编码。 字符1实际存储的值是该字符的ascii码[2]&#xff0c;即49。 如果想得到整数1&#xff0c;就需要用1减去48&#xff0c;48就是0。 1 - 0 49 - 48 1

解决模型半透明时看到内部结构的问题

大家好&#xff0c;我是阿赵。   之前在做钢铁侠线框效果的时候&#xff0c;说到过一种技术&#xff0c;这里单独拿出来再说明一下。   我们经常要做一些模型半透明效果&#xff0c;比如这个钢铁侠的模型&#xff0c;我做了一个Rim边缘光的效果&#xff0c;边缘的地方亮一点…

自定义类型详解(上)

结构体 1 结构体的声明 1.1 结构的基础知识 结构是一些值的集合&#xff0c;这些值称为成员变量。结构的每个成员可以是不同类型的变量。 1.2 结构的声明 struct tag//struct是结构体的标志&#xff0c;tag是标签;名字。 {member-list;//成员变量 }variable-list;//变量列…

linux常见下载安装工具

linux常见下载安装工具 wget、rpm、yum、apt 和 curl 是在Linux系统中常用的命令和工具&#xff0c;用于不同的系统管理和网络操作任务。以下是它们之间的联系与区别&#xff1a; wget&#xff1a; 用途&#xff1a;wget用于从网络上下载文件。它是一个命令行工具&#xff0c…