Skip to content

Commit

Permalink
Fix for issue #21
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom-Jenkins committed Jul 2, 2024
1 parent dc1361c commit e2b9857
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
4 changes: 3 additions & 1 deletion R/func_mapmixture.R
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ mapmixture <- function(
# stop("Error downloading data from Natural Earth. Please check internet connection.")
# })

# Cluster column order
cluster_col_order <- colnames(admixture_df)[3:ncol(admixture_df)]

# Standardise input data ----
tryCatch({
Expand Down Expand Up @@ -173,7 +175,7 @@ mapmixture <- function(

# Create a vector of default cluster names if parameter not set
if (is.null(cluster_names)) {
cluster_names <- colnames(admix_coords)[4:ncol(admix_coords)]
cluster_names <- cluster_col_order
}

# Do these validation checks if basemap object is not NULL
Expand Down
4 changes: 4 additions & 0 deletions R/func_process_input_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ standardise_data <- function(df, type = "admixture") {

# Convert all column names to lower case
colnames(df) <- stringr::str_to_lower(colnames(df))

# Rename cluster columns to cluster1-clusterN
num_clusters <- ncol(df)-2
colnames(df)[3:ncol(df)] <- rep(paste0("cluster", 1:num_clusters))
}

# Process coordinates tibble
Expand Down
10 changes: 8 additions & 2 deletions R/func_structure_plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,14 @@ structure_plot <- function(admixture_df,
stop("Invalid input: admixture_df should be a data.frame or tibble in the correct format. Run ?structure_plot to check valid input format.")
}

# Cluster column order
cluster_col_order <- colnames(admixture_df)[3:ncol(admixture_df)]

# Standardise input data ----
admixture_df <- standardise_data(admixture_df, type = "admixture")

# Number of clusters
num_clusters <- length(colnames(admixture_df[3:length(admixture_df)]))
num_clusters <- ncol(admixture_df)-2

# Edit the names of the first two column headings
colnames(admixture_df)[1] <- "site"
Expand Down Expand Up @@ -108,7 +114,7 @@ structure_plot <- function(admixture_df,

# Create a vector of default cluster names if parameter not set
if (is.null(cluster_names)) {
cluster_names <- colnames(admixture_df)[3:ncol(admixture_df)]
cluster_names <- cluster_col_order
}

# Execute this code if type = "structure" ----
Expand Down
6 changes: 3 additions & 3 deletions man/structure_plot.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e2b9857

Please sign in to comment.