我正在尝试使用 ggplot2 中的 labeller 函数来标记多面图。当我运行我的代码时,如果我尝试在变量的重构中包含标签(即第 5 和第 4 个方面标签未按应有的方式切换),或者标签器似乎不适用,我会得到错误标记的方面如果在重构之外使用新标签,但顺序是正确的。为每种情况附加的图像,以及我试图用作标签的变量。我在这里错过了一步吗?
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
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