在R中,当元素从一个向量传递到子向量时,如何可视化这些元素?

在R中,当元素从一个向量传递到子向量时,如何可视化这些元素?,r,ggplot2,data-visualization,visualization,graph-visualization,R,Ggplot2,Data Visualization,Visualization,Graph Visualization,我将首先介绍我的问题 我有一个由20000个元素组成的大向量: Grand_Vector = c(1,5,26,153,73,41,64,15,78,23,5212,62,5231,532,52,64,2,52,75,32,525,11,42.......,7685,37) 我还有其他向量叫做小向量1,小向量2,等等。。可能有来自Grand\u Vector的一些元素: smaller_vector1 = c(1,11,6,26,33,13) # has 1, 26, and 26 from

我将首先介绍我的问题

我有一个由20000个元素组成的大向量:

Grand_Vector = c(1,5,26,153,73,41,64,15,78,23,5212,62,5231,532,52,64,2,52,75,32,525,11,42.......,7685,37)
我还有其他向量叫做
小向量1
小向量2
,等等。。可能有来自
Grand\u Vector
的一些元素:

smaller_vector1 = c(1,11,6,26,33,13) # has 1, 26, and 26 from Grand_vector
smaller_vector2 = c(73,5231,2,52,7685,1111) # has 73, 5231, 7685 and 52 from Grand_vector
.
.
.
smaller_vector20 = c(26,153,73,41,64,15) # all the elements are from Grand_Vector
现在的问题是,每一个
小向量
s都可以有更小的向量
小向量

tiny_vector1 = c(1,11,20) # contains 1 and 11 from smaller_vector1
tiny_vector2 = c(6,26, 153, 41,1111)# contains elements from smaller_vector1, smaller_vector2, and smaller vector20
.
.
.
总之,我有5个级别:

  • 大向量
  • 更小的向量
  • 微小向量
  • 微小向量
  • 最小向量
  • 目标:可视化
    Grand\u Vector
    的元素如何以与
    Grand\u Vector
    具有“相似性”百分比的树状结构传递给较小的向量

    我试图搜索一个允许我这样做的包,但我不确定它是否存在


    提前感谢您

    如果您的向量不在列表中,您需要在每个循环中使用
    get(粘贴(…)
    来获取向量,这并不理想。但请检查这是否有效:

    proportions = list()
    for(a in 1:n_smaller_vector){#n is the number of smaller vectors you have
      smaller_vector = get(paste("smaller_vector", a, sep=""))
      proportions[[a]] = sum(smaller_vector %in% grand_vector)/length(grand_vector)
      
      for(b in 1:n_tiny_vector){
        tiny_vector = get(paste("tiny_vector", a, sep=""))
        proportions[[a]][[b]] = sum(tiny_vector %in% smaller_vector)/length(smaller_vector)
        
        for(c in 1:n_tinier_vector){
          tinier_vector = get(paste("tinier_vector", a, sep=""))
          proportions[[a]][[b]][[c]] = sum(tinier_vector %in% tiny_vector)/length(tiny_vector)
          
          for(d in 1:n_tiniest_vector){
            tiniest_vector = get(paste("tiniest_vector", a, sep=""))
            proportions[[a]][[b]][[c]][[d]] = sum(tiniest_vector %in% tinier_vector)/length(tinier_vector)
          }
        }
      }
    }
    
    同样的事情,但给列表命名:

    proportions = list()
    for(a in 1:n_smaller_vector){#n is the number of smaller vectors you have
      name_a = paste("smaller_vector", a, sep="")
      smaller_vector = get(name_a)
      proportions[[name_a]] = sum(smaller_vector %in% grand_vector)/length(grand_vector)
      
      for(b in 1:n_tiny_vector){
        name_b = paste("tiny_vector", a, sep="")
        tiny_vector = get(name_b)
        proportions[[name_a]][[name_b]] = sum(tiny_vector %in% smaller_vector)/length(smaller_vector)
        
        for(c in 1:n_tinier_vector){
          name_c = paste("tinier_vector", a, sep="")
          tinier_vector = get(name_c)
          proportions[[name_a]][[name_b]][[name_c]] = sum(tinier_vector %in% tiny_vector)/length(tiny_vector)
          
          for(d in 1:n_tiniest_vector){
            name_d = paste("tiniest_vector", a, sep="")
            tiniest_vector = get(name_d)
            proportions[[name_a]][[name_b]][[name_c]][[name_d]] = sum(tiniest_vector %in% tinier_vector)/length(tinier_vector)
          }
        }
      }
    }
    

    每个向量都在一个单独的变量中?你不能在矩阵或列表中为每种类型创建它们(这将有助于编码)?我认为你需要更具体地描述你希望可视化的样子?它像冲积图吗?如果向量不在列表中,这会很麻烦。提示是相似性比例由
    length(其中(较小的向量1%在%Grand\u向量中))/length(较小的向量1)
    给出。要为这么多元素生成树状结构,您可能需要一个递归函数,这将要求您的数据存储在一个列表中(或每个级别至少一个列表)