R 贴标机在facet_网格中重构后不应用标签

R 贴标机在facet_网格中重构后不应用标签,r,ggplot2,visualization,facet,facet-grid,R,Ggplot2,Visualization,Facet,Facet Grid,我正在尝试使用ggplot2中的labeller函数来标记刻面图。当我运行我的代码时,如果我试图在我的变量重构中包含标签,我会得到错误的刻面标签(即,第五和第四刻面标签没有按照预期进行切换),或者如果在重构之外使用,labeller似乎没有应用新标签,但顺序是正确的。为每种情况附加的图像,以及我试图用作标签的变量。我在这里漏了一步吗 dnr_names <- c('ND','GD','APD','TTD','MD') names(dnr_names) <- c(1,2,3,4,5

我正在尝试使用ggplot2中的labeller函数来标记刻面图。当我运行我的代码时,如果我试图在我的变量重构中包含标签,我会得到错误的刻面标签(即,第五和第四刻面标签没有按照预期进行切换),或者如果在重构之外使用,labeller似乎没有应用新标签,但顺序是正确的。为每种情况附加的图像,以及我试图用作标签的变量。我在这里漏了一步吗

dnr_names <- c('ND','GD','APD','TTD','MD')
  names(dnr_names) <- c(1,2,3,4,5)
dnr\u名称
D1 <- ggplot(fsom_neurons_meta_norm) +
      aes(x = MetaDisease, fill = Meta, weight = meta_n_norm) +
      geom_bar(position = "dodge") +
      scale_fill_manual(labels = c(1,2,3,4,5,6,7,8,9,10,11), values = color6) +
      labs(x = "Cluster types", y = "Cluster proportions (relative to total region)", title = "Neuronal populations across de novo regions", fill = "Cluster") +
      scale_x_discrete(labels=c("D", "ND")) +
      theme_minimal() +
      theme1a +
      theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) +#gets rid of lines
      facet_grid(cols = vars(factor(de_novo_regions, levels = c(1,2,3,5,4))), labeller = labeller(de_novo_regions = dnr_names))
    
D1
D1 <- ggplot(fsom_neurons_meta_norm) +
      aes(x = MetaDisease, fill = Meta, weight = meta_n_norm) +
      geom_bar(position = "dodge") +
      scale_fill_manual(labels = c(1,2,3,4,5,6,7,8,9,10,11), values = color6) +
      labs(x = "Cluster types", y = "Cluster proportions (relative to total region)", title = "Neuronal populations across de novo regions", fill = "Cluster") +
      scale_x_discrete(labels=c("D", "ND")) +
      theme_minimal() +
      theme1a +
      theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) +#gets rid of lines
      facet_grid(cols = vars(factor(de_novo_regions, levels = c(1,2,3,5,4), labels = dnr_names)))

D1