Skip to content

Commit

Permalink
Added legendrow and legendspacing
Browse files Browse the repository at this point in the history
  • Loading branch information
royfrancis committed Aug 14, 2019
1 parent 08663cc commit b8e7660
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 14 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Type: Package
Title: Tabulate, analyse and visualise admixture proportions from STRUCTURE, TESS, BAPS, ADMIXTURE and tab-delimited q-matrices
files
Version: 2.3.0
Date: 2019-08-11
Date: 2019-08-14
Author: Roy Mathew Francis
Authors@R: person("Roy", "Francis", email = "roy.m.francis@outlook.com",role = c("aut", "cre"))
Maintainer: Roy Mathew Francis <roy.m.francis@outlook.com>
Expand Down
4 changes: 3 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# pophelper 2.3.0

* 11-Aug-2019
* Built on R-3.6.0
* Built on R-3.6.0. Min req R-3.5.0.
* Removed CLUMPP and DISTRUCT executables
* 'useexe' argument in ClumppExport() deprecated.
* Added alignK() function for label switching within and between K
Expand All @@ -13,6 +13,8 @@
* Added function sortQ() to sort runs in a qlist by a run attribute
* Added function mergeQ() to merge replicate runs within K
* Added function splitQ() to split a qlist object by an attribute
* 14-Aug-2019
* Added arguments 'legendspacing' and 'legendrow' to plotQ()

# pophelper 2.2.9

Expand Down
9 changes: 8 additions & 1 deletion R/plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,8 @@ sortInd <- function(dframe=NULL,grplab=NA,selgrp=NA,ordergrp=FALSE,sortind=NA,gr
#' to 4.
#' @param legendtextsize A numeric indicating size of the legend text. Defaults
#' to 3.
#' @param legendspacing Spacing between legend items.
#' @param legendrow Number of rows of legend.
#' @param legendmargin A numeric vector of length 4 indicating top, right,
#' bottom and left margins of the legend.
#' @param barsize A numeric indicating the width of the bars. Defaults to 1.
Expand Down Expand Up @@ -924,7 +926,7 @@ plotQ <- function(qlist=NULL,imgoutput="sep",clustercol=NA,sortind=NA,grplab=NA,
pointsize=NA,pointcol="grey30",pointbgcol="grey30",pointtype="|",pointalpha=1,
linepos=0.75,linesize=NA,linecol="grey30",linetype=1,linealpha=1,
showdiv=TRUE,divgrp=NA,divcol="white",divtype="21",divsize=0.25,divalpha=1,
showlegend=FALSE,legendlab=NA,legendpos="right",legendkeysize=4,legendtextsize=3,legendmargin=c(0.5,0.5,0.5,0),
showlegend=FALSE,legendlab=NA,legendpos="right",legendkeysize=4,legendtextsize=3,legendspacing=2,legendrow=NULL,legendmargin=c(0.5,0.5,0.5,0),
barsize=1,barbordersize=0,barbordercolour=NA,
showyaxis=FALSE,showticks=FALSE,ticksize=0.1,ticklength=0.03,
outputfilename=NA,imgtype="png",height=NA,width=NA,dpi=300,units="cm",
Expand Down Expand Up @@ -1154,6 +1156,7 @@ plotQ <- function(qlist=NULL,imgoutput="sep",clustercol=NA,sortind=NA,grplab=NA,
scale_x_continuous(breaks=df2$order_ind,labels=df2$ind,expand=c(0,0))+
scale_y_continuous(expand=c(0,0))+
scale_fill_manual(values=coll,labels=legendlab1)+
guides(fill=guide_legend(nrow=legendrow,byrow=TRUE))+
facet_wrap(~run,labeller=labeller(run=facetnames),strip.position=sppos,scales="fixed",nrow=1)+
get(theme)(base_family=font,base_size=basesize)

Expand All @@ -1163,6 +1166,7 @@ plotQ <- function(qlist=NULL,imgoutput="sep",clustercol=NA,sortind=NA,grplab=NA,
legend.title=element_blank(),
legend.key.size=grid::unit(legendkeysize,"points"),
legend.text=element_text(size=legendtextsize,colour=indlabcol),
legend.spacing.x=grid::unit(legendspacing,"points"),
legend.spacing=grid::unit(0,"points"),
legend.justification=legendpos,
legend.margin=margin(legendmargin[1],legendmargin[2],legendmargin[3],legendmargin[4],"points"),
Expand Down Expand Up @@ -1543,13 +1547,15 @@ plotQ <- function(qlist=NULL,imgoutput="sep",clustercol=NA,sortind=NA,grplab=NA,
scale_x_continuous(breaks=df3$order_ind,labels=df3$ind,expand=c(0,0))+
scale_y_continuous(expand=c(0,0))+
scale_fill_manual(values=coll,labels=legendlab1)+
guides(fill=guide_legend(nrow=legendrow,byrow=TRUE))+
get(theme)(base_family=font,base_size=basesize)
}else{
gg_plot_panel <- ggplot2::ggplot(data=df3,aes(x=order_cumulative,y=value,fill=variable))+
geom_bar(width=barsize,size=barbordersize,colour=barbordercolour,stat="identity",position="fill",na.rm=na.rm)+
scale_x_continuous(breaks=df3$order_cumulative,labels=df3$ind,expand=c(0,0))+
scale_y_continuous(expand=c(0,0))+
scale_fill_manual(values=coll,labels=legendlab1)+
guides(fill=guide_legend(nrow=legendrow,byrow=TRUE))+
get(theme)(base_family=font,base_size=basesize)
}

Expand All @@ -1566,6 +1572,7 @@ plotQ <- function(qlist=NULL,imgoutput="sep",clustercol=NA,sortind=NA,grplab=NA,
legend.title=element_blank(),
legend.key.size=grid::unit(legendkeysize,"points"),
legend.text=element_text(size=legendtextsize,colour=indlabcol),
legend.spacing.x=grid::unit(legendspacing,"points"),
legend.spacing=grid::unit(0,"points"),
legend.justification=legendpos,
legend.margin=margin(legendmargin[1],legendmargin[2],legendmargin[3],legendmargin[4],"points"),
Expand Down
2 changes: 1 addition & 1 deletion R/qlist.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#' @param qlist A qlist object.
#' @return Nothing.
#' @details Returns error if the object is not a list, contents are not data.frames or NA list elements or missing run labels. Warnings are generated for non standard column labels or missing attributes 'ind' and 'k'. Warnings can be fixed by running \code{\link{as.qlist}}.
#' @example
#' @examples
#' sfiles <- list.files(path=system.file("files/structure",package="pophelper"),
#' full.names=TRUE)
#' slist <- readQ(sfiles)
Expand Down
6 changes: 6 additions & 0 deletions man/is.qlist.Rd

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

20 changes: 12 additions & 8 deletions man/plotQ.Rd

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

4 changes: 2 additions & 2 deletions vignettes/index.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fc <- captioner::captioner(prefix="Fig. ")

This vignette/tutorial aims to demonstrate the use of R package `pophelper`. This package contains functions that are useful for processing output results from programs used in the analysis of population structure such as ADMIXTURE^1^, FASTSTRUCTURE^6^, STRUCTURE^5^, TESS^3^, BAPS^8^ and any q-matrix output as a numeric tabular delimited file.

These softwares are popular programs used to discriminate populations, to determine population structure and to reveal the genetic composition of individuals using molecular markers. These programs generally use allelic frequency information to assign individuals to a pre-defined number of populations (*K*). The assignment is usually run for a range of *K* such as from *K*=2 to *K*=10. Multiple repeats are also usually carried out for each *K*. Each output file for each repeat of *K* showing the assignment probabilities of all individuals is referred to as the run file, cluster file or q-matrix file. `pophelper` has a set of functions that include reading into R, tabulating, summarising and plotting these run files.
These software are popular programs used to discriminate populations, to determine population structure and to reveal the genetic composition of individuals using molecular markers. These programs generally use allelic frequency information to assign individuals to a pre-defined number of populations (*K*). The assignment is usually run for a range of *K* such as from *K*=2 to *K*=10. Multiple repeats are also usually carried out for each *K*. Each output file for each repeat of *K* showing the assignment probabilities of all individuals is referred to as the run file, cluster file or q-matrix file. `pophelper` has a set of functions that include reading into R, tabulating, summarising and plotting these run files.

This vignette covers the use of all important functions in the `pophelper` package. The demonstration is ordered in the manner of a typical workflow. Input and output codes are printed in a font different from body text like `this`.

Expand Down Expand Up @@ -816,7 +816,7 @@ sapply(slist1[c(1,3)],ncol)
# modified for this document
p1 <- plotQ(slist1[1],returnplot=T,exportplot=F,quiet=T,basesize=11,
showlegend=T, legendlab=c("group1","group2"),
legendkeysize=10,legendtextsize=10,legendmargin=c(2,2,2,0))
legendkeysize=10,legendtextsize=10,legendmargin=c(2,2,2,0),legendrow=1)
p2 <- plotQ(slist1[c(1,3)],imgoutput="join",returnplot=T,exportplot=F,quiet=T,basesize=11,
showlegend=T, legendlab=c("group1","group2","group3"),
Expand Down

0 comments on commit b8e7660

Please sign in to comment.