bensutherland / simple_pop_stats

A short analysis of population statistics given specific inputs
5 stars 1 forks source link

pca_from_genind.r not using default colour option. #17

Open erondeau opened 3 years ago

erondeau commented 3 years ago

Issue is in pca_from_genind.r, colour_file = NULL. If is.null(colour_file), it creates a pallette.

  if(is.null(colour_file)){

    # Set colours default
    library(RColorBrewer)
    cols1 <- brewer.pal(n = nPop(my.data), name = "Paired")
    cols2 <- brewer.pal(n = (nPop(my.data)-length(cols1)), name = "Spectral")
    cols <- c(cols1, cols2)

  } else if(!is.null(colour_file)){

    # Reporting
    print(paste0("Using custom colours file from ", colour_file))

    # Input colour file
    colours.df <- read.table(file = colour_file, header = T, sep = ",", stringsAsFactors = F)

  }

However, later in the script, it filters colours.df to create the colours and then ordered_colours df.

  ## Create a colours vector
  # Select only the pops that are in the data
  colours <- filter(colours.df, collection %in% unique(pca.scores$pop))

  # Put into alphabetic order by collection (the plotting order, and legend order)
  colours <- colours[order(colours$collection), ]

Because this isn't created in the if/else above when colours.file = NULL, the script bails. Should be easy to patch, but won't address it at the moment.