Skip to content

Commit

Permalink
Merge pull request #73 from royfrancis/v2.3.1
Browse files Browse the repository at this point in the history
Legend sorting fixed
  • Loading branch information
royfrancis authored Dec 29, 2020
2 parents 1549f50 + 70d7b13 commit 3807852
Show file tree
Hide file tree
Showing 37 changed files with 105 additions and 85 deletions.
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 26 additions & 3 deletions R/plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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))+
Expand Down Expand Up @@ -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
}
Expand All @@ -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
Expand Down Expand Up @@ -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))
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion docs/404.html

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

2 changes: 1 addition & 1 deletion docs/articles/index.html

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

Loading

0 comments on commit 3807852

Please sign in to comment.