Closed apoosakkannu closed 1 year ago
Please use color_values
parameter to adjust the color palette in each plot. You should select corresponding colors to assign color_values
since the legend are different.
Thanks. As I am using the loop it was a bit difficult for me. the code is following,
library(ggplot2) library(patchwork) library(magrittr) library(gridExtra)
dataset2$sample_table$Country <- factor(dataset2$sample_table$Country, levels = c("Finland", "France", "Latvia", "Denmark", "Poland"))
theme_set(theme_gray(base_size = 15))
alphaplot_list <- list()
t_country_alpha <- trans_alpha$new(dataset = dataset2, group = "Country", by_group = "Host_taxa") t_country_alpha$cal_diff(method = "wilcox") country_chao <- t_country_alpha$plot_alpha(measure = "Chao1", add_sig = FALSE) + lims(y = c(0, 3500)) country_shannon <- t_country_alpha$plot_alpha(measure = "Shannon", add_sig = FALSE) + lims(y = c(0, 8))
alphaplot_list[[1]] <- country_chao alphaplot_list[[2]] <- country_shannon
alpha_plot<-gridExtra::grid.arrange(grobs = alphaplot_list, ncol = 2)
allgroups <- unique(dataset2$sample_table[, "Host_taxa"])
betaplot_list <- list()
permanova_list <- list()
dispersion_list <- list()
for (i in allgroups) {
tmp <- clone(dataset2) tmp$sample_table <- subset(tmp$sample_table, Host_taxa == i) tmp$tidy_dataset()
plot_title <- paste(i)
tmp_beta <- trans_beta$new(dataset = tmp, group = "Country", measure = "bray") tmp_beta$cal_ordination(ordination = "PCoA")
betaplot_list[[i]] <- tmp_beta$plot_ordination(plot_color = "Country", plot_shape = "Country", plot_type = c("point", "ellipse")) + ggtitle(plot_title)
tmp_beta$cal_manova(manova_all = TRUE)
permanova_list[[i]] <- tmp_beta$res_manova
tmp_beta$cal_betadisper()
dispersion_list[[i]] <- tmp_beta$res_betadisper$tab
rm(tmp, tmp_beta, tmp_df) }
permanova_df <- do.call(rbind, permanova_list)
write.csv(permanova_df, "permanova_results.csv", row.names = TRUE)
dispersion_df <- do.call(rbind, dispersion_list)
write.csv(dispersion_df, file = "beta_dispersion_results.csv", row.names = TRUE)
beta_plot<-wrap_plots(betaplot_list, ncol = 2)
rm(allgroups, plot_list, permanova_list, dispersion_list)
countryplot_list <- list()
countryplot_list[[1]] <- alpha_plot countryplot_list[[2]] <- beta_plot
country_plot <- wrap_plots(countryplot_list, ncol = 1)
On Fri, Apr 14, 2023 at 4:47 AM Chi Liu @.***> wrote:
Please use color_values parameter to adjust the color palette in each plot. You should select corresponding colors to assign color_values since the legend are different.
— Reply to this email directly, view it on GitHub https://github.com/ChiLiubio/microeco/issues/221#issuecomment-1507813797, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMC3WZSUCJN256KOCBEFTNLXBCUCXANCNFSM6AAAAAAW5TOX6Y . You are receiving this because you authored the thread.Message ID: @.***>
You can allocate colors in the color_values
parameter according to your groups selected to show in the figure no matter what style you are using.
Hi, To assign the same colors to each country in different plots, even when some countries are not present in all plots,
could you please give me idea of how to assign same colors for different levels of a factor? example figure below,