Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 在矩阵布局中绘制直方图以分析簇_R_Layout_Ggplot2 - Fatal编程技术网

R 在矩阵布局中绘制直方图以分析簇

R 在矩阵布局中绘制直方图以分析簇,r,layout,ggplot2,R,Layout,Ggplot2,我正试图编写一个大函数来执行集群的分析 目前,我正在努力完成最后一项任务: 在矩阵布局中绘制直方图,其中行表示集群,列表示变量。 考虑到以下示例: df <- data.frame(x = rnorm(50,5), y = rnorm(50, 10)) 以下是该地块的布置方式: 显然,最终的可视化比这更清晰,因为 根据该簇的相对重要性对图进行排序 对于每个集群,只有该集群的文本描述的绘图 对于分类变量,将使用piechart 然而,主要的问题是理解如何创建矩阵布局,在这里我可以插入

我正试图编写一个大函数来执行集群的分析

目前,我正在努力完成最后一项任务:
在矩阵布局中绘制直方图,其中行表示集群,列表示变量。

考虑到以下示例:

df <- data.frame(x = rnorm(50,5), y = rnorm(50, 10))
以下是该地块的布置方式:

显然,最终的可视化比这更清晰,因为

  • 根据该簇的相对重要性对图进行排序
  • 对于每个集群,只有该集群的文本描述的绘图
  • 对于分类变量,将使用piechart
然而,主要的问题是理解如何创建矩阵布局,在这里我可以插入所有的绘图

更新 这是我根据你的建议得到的。

用cowplot怎么样

library("cowplot")
plot_grid(plot11,plot12,plot13,plot21,ncol = 2, nrow = 2)
或者,如果可以使用函数填充绘图列表,则可以传递该列表:

plotList<-list(plot11,plot12,plot13,plot21)
plot_grid(plotlist=plotList,ncol = 2, nrow = 2)
plotList使用cowplot怎么样

library("cowplot")
plot_grid(plot11,plot12,plot13,plot21,ncol = 2, nrow = 2)
或者,如果可以使用函数填充绘图列表,则可以传递该列表:

plotList<-list(plot11,plot12,plot13,plot21)
plot_grid(plotlist=plotList,ncol = 2, nrow = 2)

plotList我的建议是处理一个converinant表单来创建一个字符串并像那样使用它(multiplot函数的代码当然不是我的):


multiplot我的建议是处理一个converinant表单来创建一个字符串并像那样使用它(multiplot函数的代码当然不是我的):


multiplot你用
multiplot
试过什么吗?我试过multiplot,但没能得到结果。也许我做错了什么,因为“叠加”一个的绘图编辑:multiplot可以工作,但必须在函数中手动写入ggplot对象名称。这意味着我无法动态操纵绘图为什么说“动态”?如果绘图的数量是固定的,我不明白你的意思。显然我不能写多点图(地块11、地块12、地块13、地块14、地块15、地块21、地块22、地块23、地块24、地块25、地块31、地块32、地块33、地块34、地块35、地块41、地块42、地块43、地块44、地块45……)。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。我需要找到一种动态和自动的方法来实现这一点。动态是因为外观的顺序是由另一个函数决定的。您是否尝试了使用
multiplot
?我尝试了multiplot,但未能获得结果。可能我做了一些错误的事情,因为“叠加”一个编辑:multiplot可以工作,但您必须在函数中手动写入ggplot对象名称。这意味着我无法动态操作绘图为什么您的意思是“动态”?如果绘图的数量是固定的,我不明白您的意思。显然,我无法写入multiplot(地块11、地块12、地块13、地块14、地块15、地块21、地块22、地块23、地块24、地块25、地块31、地块32、地块33、地块34、地块35、地块41、地块42、地块43、地块44、地块45……)。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。我需要找到一种动态和自动的方法来实现这一点。动态是因为外观的顺序由另一个函数决定。cowplot的问题是它既不是动态的,也不是自动的。正如我所写的,解决方案不需要写“(地块11、地块12、地块13、地块14、地块15、地块21、地块22、地块23、地块24、地块25、地块31、地块32、地块33、地块34、地块35、地块41、地块42、地块43、地块44、地块45等)。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。‌​....................‌​....................‌​....................‌​....................‌​....................‌​....................‌​....................‌​....................‌​..)“如果您可以使用函数填充绘图列表,您可以将此列表传递到绘图网格中,如果这对您有帮助,请检查我的更新答案使用list()的想法可能看起来正确,但是绘图没有正确显示cowplot的问题是它既不是动态的,也不是自动的。正如我所写的,解决方案不需要写入”(地块11、地块12、地块13、地块14、地块15、地块21、地块22、地块23、地块24、地块25、地块31、地块32、地块33、地块34、地块35、地块41、地块42、地块43、地块44、地块45等)。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。‌​....................‌​....................‌​....................‌​....................‌​....................‌​....................‌​....................‌​....................‌​..)“如果您可以使用函数填充绘图列表,您可以将此列表传递到绘图网格中,如果这有助于您,请检查我的更新答案使用list()的想法似乎正确,但绘图显示不正确
 multiplot <- function(..., plotlist=NULL, file, cols=1, layout=NULL) {
  require(grid)

  # Make a list from the ... arguments and plotlist
  plots <- c(list(...), plotlist)

  numPlots = length(plots)

  # If layout is NULL, then use 'cols' to determine layout
  if (is.null(layout)) {
    # Make the panel
# ncol: Number of columns of plots
# nrow: Number of rows needed, calculated from # of cols
layout <- matrix(seq(1, cols * ceiling(numPlots/cols)),
                 ncol = cols, nrow = ceiling(numPlots/cols))
  }

  if (numPlots==1) {
print(plots[[1]])

  } else {
# Set up the page
grid.newpage()
pushViewport(viewport(layout = grid.layout(nrow(layout), ncol(layout))))

# Make each plot, in the correct location
for (i in 1:numPlots) {
  # Get the i,j matrix positions of the regions that contain this subplot
  matchidx <- as.data.frame(which(layout == i, arr.ind = TRUE))

  print(plots[[i]], vp = viewport(layout.pos.row = matchidx$row,
                                  layout.pos.col = matchidx$col))
    }
  }
}

string_plots <- "multiplot(plotlist = list(plot11,plot12, plot13, plot21, plot22, plot23, plot31, plot32), cols = 3)"

eval(parse(text=string_plots))