Labeller not applying labels after refactoring in facet_grid

Viewed 91

I'm trying to use the labeller function within ggplot2 to label faceted plots. When I run my code I get mislabeled facets if I try to include labels in the refactoring of my variable (i.e. the 5th and 4th facet labels aren't switched as they're supposed to be), or labeller doesn't seem to apply the new labels if used outside the refactoring, but the order is correct. Images attached for each situation, as well as the variable I'm trying to use as labels. Am I missing a step here?

dnr_names <- c('ND','GD','APD','TTD','MD')
  names(dnr_names) <- c(1,2,3,4,5)
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

enter image description here

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

enter image description here

0 Answers
Related