diff --git a/NEWS b/NEWS index a359655..06bd06d 100644 --- a/NEWS +++ b/NEWS @@ -10,6 +10,7 @@ pophelper 2.3.1 * Automatic CI testing added * Fixed an issue where runs merged using mergeQ() produced a warning about missing attributes. * In function clumppExport() and distructExport(), argument 'path' changed to 'exportpath' to be consistent with other functions. +* Legend is now sorted numerically * Fixed minor errors in documentation. pophelper 2.3.0 diff --git a/NEWS.md b/NEWS.md index 608bb56..01f65a5 100644 --- a/NEWS.md +++ b/NEWS.md @@ -10,6 +10,7 @@ * Automatic CI testing added * Fixed an issue where runs merged using mergeQ() produced a warning about missing attributes. * In function clumppExport() and distructExport(), argument 'path' changed to 'exportpath' to be consistent with other functions. +* Legend is now sorted numerically * Fixed minor errors in documentation. # pophelper 2.3.0 diff --git a/R/plot.R b/R/plot.R index 068129b..b1f44a4 100644 --- a/R/plot.R +++ b/R/plot.R @@ -1164,7 +1164,12 @@ plotQ <- function(qlist=NULL,imgoutput="sep",clustercol=NA,sortind=NA,grplab=NA, # legendlab if(any(is.na(legendlab))) { - legendlab1 <- levels(factor(as.character(df2$variable))) + if(all(grepl("Cluster",df2$variable))){ + legendlab1 <- paste0("Cluster",sort(as.integer(unique(gsub("Cluster","",df2$variable))))) + }else{ + legendlab1 <- levels(factor(as.character(df2$variable))) + } + }else{ legendlab1 <- legendlab } @@ -1194,7 +1199,12 @@ plotQ <- function(qlist=NULL,imgoutput="sep",clustercol=NA,sortind=NA,grplab=NA, width1 <- as.numeric(dimtemp[2]) grplabheight1 <- as.numeric(dimtemp[3]) units1 <- as.character(dimtemp[4]) - + + # order legend numerically + if(all(grepl("Cluster",df2$variable))){ + df2$variable <- factor(df2$variable,levels=paste0("Cluster",sort(as.integer(unique(gsub("Cluster","",df2$variable)))))) + } + ## COMMON PLOT TOP PANEL --------------------------------------------------- # create plot gg_plot_panel <- ggplot(data=df2,aes(x=order_ind,y=value,fill=variable))+ @@ -1563,7 +1573,11 @@ plotQ <- function(qlist=NULL,imgoutput="sep",clustercol=NA,sortind=NA,grplab=NA, # legendlab if(any(is.na(legendlab))) { - legendlab1 <- levels(factor(as.character(df3$variable))) + if(all(grepl("Cluster",df3$variable))){ + legendlab1 <- paste0("Cluster",sort(as.integer(unique(gsub("Cluster","",df3$variable))))) + }else{ + legendlab1 <- levels(factor(as.character(df3$variable))) + } }else{ legendlab1 <- legendlab } @@ -1583,6 +1597,11 @@ plotQ <- function(qlist=NULL,imgoutput="sep",clustercol=NA,sortind=NA,grplab=NA, if(any(is.na(clustercol))) coll <- getColours(as.integer(max(kvec))) if(length(coll) < max(kvec)) stop(paste0("plotQ: Number of colours (",length(coll),") is less than the number of clusters (",max(kvec),").")) + # order legend numerically + if(all(grepl("Cluster",df3$variable))){ + df3$variable <- factor(df3$variable,levels=paste0("Cluster",sort(as.integer(unique(gsub("Cluster","",df3$variable)))))) + } + ## COMMON PLOT TOP PANEL ---------------------------------------------------- # create plot # when unsorted or sorting is by label, x-axis is by individual order @@ -2312,6 +2331,7 @@ plotQMultiline <- function(qlist=NULL,spl=NA,lpp=NA,clustercol=NA,sortind=NA,grp if(length(coll) < ncol(dff)) stop(paste0("plotQMultiline: Number of colours (",length(coll),") is less than the number of clusters (",ncol(dff),").")) if(any(is.na(legendlab))) legendlab1 <- colnames(dff) + #if(any(is.na(legendlab))) legendlab1 <- paste0("Cluster",sort(as.integer(unique(gsub("Cluster","",dff$variable))))) dff$ind <- factor(rownames(dff),levels=rownames(dff)) #dff$ind <- as.character(rownames(dff)) @@ -2325,6 +2345,9 @@ plotQMultiline <- function(qlist=NULL,spl=NA,lpp=NA,clustercol=NA,sortind=NA,grp dff[[selgrp]] <- factor(dff[[selgrp]],levels=rle(dff[[selgrp]])$values) } + # order legend numerically + #dff$variable <- factor(dff$variable,levels=paste0("Cluster",sort(as.integer(unique(gsub("Cluster","",dff$variable)))))) + # split and plot rows dlist <- split(dff,dff$rows) plist <- vector("list",length=nr2) diff --git a/docs/404.html b/docs/404.html index 1b7ba1f..02f4425 100644 --- a/docs/404.html +++ b/docs/404.html @@ -118,7 +118,7 @@