输入help(autoplot.prcomp) 可以了解到更多的其他选择。 更多的选择请参考 help(autoplot.ts)。 autoplot(Canada, facets = FALSE) autoplot 也可以理解其他的时间序列类别。 ) autoplot(smoothed) p <- autoplot(filtered) autoplot(smoothed, ts.colour = 'blue', p = p) KFAS包 library , states="trend") p <- autoplot(filtered) autoplot(trend, ts.colour = 'blue', p = p) stats包 可支持的stats
输入help(autoplot.prcomp) 可以了解到更多的其他选择。 autoplot(prcomp(df), data = iris, colour = 'Species') ? 更多的选择请参考help(autoplot.ts)。 autoplot(AirPassengers, ts.colour = 'red', ts.linetype = 'dashed') ? autoplot(Canada, facets = FALSE) ? autoplot 也可以理解其他的时间序列类别。 p <- autoplot(filtered) autoplot(smoothed, ts.colour = 'blue', p = p) ? trend <- signal(smoothed, states="trend") p <- autoplot(filtered) autoplot(trend, ts.colour = 'blue',
R包的使用 01 时序分析可视化 使用AirPassengers数据集绘制基本时序分析图片 #AirPassengers数据集 autoplot(AirPassengers) 使用 ts.colour 和ts.linetype改变线的颜色和形状 autoplot(AirPassengers, ts.colour = 'red', ts.linetype = 'dashed',xlab = "time ::install("strucchange") library(strucchange) autoplot(breakpoints(Nile ~ 1)) 多变量的时序分析: BiocManager ,只画后3列 autoplot(Canada[,-1])#fig.2 #使用 facets = FALSE 可以把所有变量画在一条轴上。 [, -5] # 主成分分析 pca <- prcomp(df, scale. = TRUE) # 绘图 autoplot(pca, loadings = TRUE, loadings.label =
library(GenomicFeatures) txdb<-makeTxDbFromGFF(file="practice.gff",format="gff3") 可视化 用到的 ggbio 这个包中的 **autoplot ()**这个函数 library(ggbio) autoplot(txdb, which=GRanges("CP002684.1", IRanges(100, 9000)), 可以通过fill参数设置不同的颜色 autoplot(txdb, which=GRanges("CP002684.1", IRanges(100, 9000)), names.expr image.png 不同的基因填充不同的颜色 autoplot(txdb, which=GRanges("CP002684.1", IRanges(100, 9000)), 今天就到这里了,抽时间看看下autoplot()这个函数的帮助文档
"purple") 2、ggcyto ggcyto(gs, aes(x = CD4, y = CD8)) + geom_hex(bins = 128) + geom_gate("CD8") 3、autoplot autoplot(fs, "CD4") autoplot(fs, "CD4", "CD8", bins = 64) autoplot(gs, c("CD4", "CD8"), bins = 64) in-line transformation 它是由专门为细胞计数设计的不同scales layers完成的 #先绘制原始的scale data(GvHD) fr <- GvHD[[1]] p <- autoplot ggCyto还提供了拼图设置布局的功能 gh <- gs[[1]] nodes <- gs_get_pop_paths(gh, path = "auto")[c(3:9, 14)] nodes p <- autoplot (gh, nodes, bins = 64) class(p) p gt <- ggcyto_arrange(p, nrow = 1) class(gt) p2 <- autoplot(gh_pop_get_data
library(ggcyto) autoplot(X, "FL1-H","FL2-H") ? exprs(fs[[1]][1:12,])##获取数据 autoplot(fs, "FL1-H","FL2-H") ? compensate(fs, comp) library(gridExtra) transList <- estimateLogicle(x,c("V450-A","V545-A")) p1 <- autoplot (transform(x, transList),"V450-A", "V545-A") +ggtitle("Before") p2 <- autoplot(transform(x_comp,transList autoplot(gs[[1]])#可视化所有的门 ? 当然还可以更加细化门的分类,以及门的构成,在此我们就不再深究了。
"pregnant" #[7] "pressure" "triceps" task$select(head(task$feature_names, 3)) # 选取前三列特征变量(features) autoplot (task) # 绘图,这里只会针对目标变量来绘图 autoplot(task, type = "pairs") # 绘制配对的关联图 在上图中,红色代表的是糖尿病组,蓝色代表的是非糖尿病组。 autoplot(task, type = "duo") # 绘制duo图 上面这幅图很好地展现出糖尿病和非糖尿病人群中三个特征变量的差异,直观简洁!
classif.rpart", predict_type = "prob") learner$train(task) prediction = learner$predict(task) # 绘制默认图 autoplot (prediction) # 绘制roc图 autoplot(prediction, type = "roc") ? task = tsk("mtcars") learner = lrn("regr.lm") learner$train(task) prediction = learner$predict(task) autoplot
因为这个原因,ggplot2定义了一个自己的泛型函数autoplot(),调用它会返回一个ggplot()。 #' @importFrom ggplot2 autoplot autoplot.discrete_distr <- function(object, ...) { plot_data <- discrete_distr_data probability)) + geom_col() + coord_flip() + labs(x = "Value", y = "Probability") } 一旦定义了 autoplot (x, ...)) } 如果你不懂S3类,实现像plot()或者autoplot()这种泛型是一个不好的实践,因为这限制了包开发者自己控制S3用于实现自己的方法。 %+replace% ggplot2::theme(panel.background = ggplot2::element_blank()) } 通过,如果你为ggplot2的autoplot
使用mlr3viz包,绘制任务图 返回的是数据的相关图、分布图 library("mlr3viz") autoplot(task_mtcars, type = "pairs") ## Registered 建立任务,使用的为预置任务集 task = tsk("pima") # 只选择前三个列名,也就是特征 task$select(head(task$feature_names, 3)) # 默认绘制频率图 autoplot # 绘制配对的图 # 显示的信息较多 autoplot(task, type = "pairs") ? 同时对于回归任务也是一样的,这里就不粘贴绘制的图片了 library("mlr3viz") task = tsk("mtcars") task$select(head(task$feature_names, 3)) autoplot (task) autoplot(task, type = "pairs") 结束语 mlr3关于任务的建立更新完毕 love&peace
## truth ## response pass run ## pass 31932 9886 ## run 8819 18345 混淆矩阵可视化: autoplot classif.auc classif.acc classif.bbrier ## 0.7979179 0.7288424 0.1790592 喜闻乐见ROC曲线: autoplot (rr,type = "roc") plot of chunk unnamed-chunk-9 喜闻乐见的prc曲线: autoplot(rr, type = "prc") plot of chunk unnamed-chunk-10 箱线图: autoplot(rr, measure = msr("classif.auc")) plot of chunk unnamed-chunk-11 以上所有介绍的图形和评价方法都在之前的推文详细介绍过了
教程看群主之前的推文: 【直播】我的基因组55:简单的PCA分析千人基因组的人群分布 重复一篇Cell文献的PCA图 prcomp 用到的参数介绍 prcomp是R的stats 包(base级别)的函数; autoplot ggfortify中的函数,frame即对分出来的簇加上边界,frame.type即边界类型设定为norm; ######ggplot2太大了,得抽时间好好了解; library(ggfortify) autoplot (prcomp( df[,1:ncol(df)-1] ), data=df,colour = 'group') autoplot(prcomp( df[,1:ncol(df)-1] ),
可视化重采样结果 mlr3viz提供了一个autoplot()方法。 (rr, measure = msr("classif.auc")) img # ROC curve, averaged over 10 folds autoplot(rr, type = "roc ") img # learner predictions for first fold rr$filter(1) autoplot(rr, type = "prediction") img autoplot.ResampleResult 可视化重采样分区 Mlr3spatiotempcv提供autoplot()方法来可视化时空数据集的重采样分区。更多信息,请参阅函数参考[39]和vignette“时空可视化”[40]。 library("mlr3viz") # TPR vs FPR / Sensitivity vs (1 - Specificity) autoplot(pred, type = "roc") img
4: kknn 0.7322762 0.6779451 0.2210171 结果可视化 支持ggplot2语法,使用起来和tidymodels差不多,也是对结果直接autoplot library(ggplot2) autoplot(bmr)+theme(axis.text.x = element_text(angle = 45)) 喜闻乐见的ROC曲线: autoplot(bmr prediction$confusion truth response pass run pass 10629 3175 run 2955 6235 可视化混淆矩阵: autoplot )) classif.auc classif.acc classif.bbrier 0.8011720 0.7334087 0.1775684 喜闻乐见ROC曲线: autoplot
10622 3226 ## run 2962 6185 混淆矩阵图形版: pred_rf %>% conf_mat(play_type,.pred_class) %>% autoplot binary 0.799 可视化结果,首先是大家喜闻乐见的ROC曲线: pred_rf %>% roc_curve(truth = play_type, .pred_pass) %>% autoplot ) plot of chunk unnamed-chunk-13 pr曲线: pred_rf %>% pr_curve(truth = play_type, .pred_pass) %>% autoplot of chunk unnamed-chunk-14 gain_curve: pred_rf %>% gain_curve(truth = play_type, .pred_pass) %>% autoplot of chunk unnamed-chunk-15 lift_curve: pred_rf %>% lift_curve(truth = play_type, .pred_pass) %>% autoplot
51:60, 101:110)), test = list(c(11:20, 61:70, 111:120)) ) resampling$iters 绘制结果 library("mlr3viz") autoplot 绘制roc曲线 autoplot(rr, type = "roc") ? 结束语 对于重抽样的操作,建议在高性能的服务器上进行,或者测试数据较少或者特征较少的数据集。 love&peace
group=c(rep('group1',20),rep('group2',20))) # prcomp()主成分分析 pca_dat <- prcomp( df[,1:(ncol(df)-1)] ) autoplot sample_all); dim(sample_all) df=cbind(as.data.frame(a3),group=c(rep('group1',20),rep('group2',20))) autoplot group1',cell_num),rep('group2',cell_num))) # prcomp()主成分分析 pca_dat <- prcomp( df[,1:(ncol(df)-1)] ) autoplot as.data.frame(sample_all),group=c(rep('group1',cell_num),rep('group2',cell_num),rep('group3',cell_num))) autoplot
对比下在R的现成的PCA功能的结果 FactoMineR和factoextra配合做PCA和可视化(下图中图片名为PCA); prcomp(stats base级别)和autoplot配合做PCA和可视化 为协方差矩阵; deca_re$x ###生成名为Rplot_deca$x的图,方便与ggfortify的作图对比 plot(deca_re$x) #####ggfortify使ggplot2功能更加丰富,使autoplot 能够处理prcomp的结果 library(ggfortify) autoplot(prcomp(decathlon2.active),label=TRUE,loadings=TRUE) ######
geom_hline(aes(yintercept = 0), linetype="dashed") + geom_vline(aes(xintercept = 0) ,linetype="dashed") ####autoplot #autoplot是ggplot object ,可以在此基础上继续添加图层。 #C.whole是CCA的结果 >autoplot(C.whole) ?
four_fits %>% autoplot(metric = "roc_auc")+theme_bw() image-20220704145235120 选择最好的模型用于测试集 选择表现最好的应用于测试集 20220704145017664 可视化结果,喜闻乐见的混淆矩阵: collect_predictions(rand_res) %>% conf_mat(play_type,.pred_class) %>% autoplot 20220704145028522 喜闻乐见的ROC曲线: collect_predictions(rand_res) %>% roc_curve(play_type,.pred_pass) %>% autoplot