plotQMultiline: Plot a qlist as individual-level multiline barplot

Description Usage Arguments Details Examples

View source: R/pophelper.R

Description

Plot a qlist as individual-level barplot with multiple lines.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
plotQMultiline(qlist = NULL, spl = NA, lpp = NA, clustercol = NA,
  sortind = NA, grplab = NA, selgrp = NA, ordergrp = FALSE,
  subsetgrp = NA, grpmean = FALSE, showindlab = TRUE, useindlab = FALSE,
  indlabwithgrplab = FALSE, indlabsep = " ", indlabsize = 5,
  indlabangle = 90, indlabvjust = 0.5, indlabhjust = 1,
  indlabcol = "grey30", indlabspacer = 1.5, showgrplab = TRUE,
  grplabsize = 7, grplabcol = "grey30", grplabbgcol = "#DCDCDC",
  showtitle = FALSE, titlelab = NA, titlehjust = 0, titlevjust = 0.5,
  titlesize = 9, titlecol = "grey30", titleface = "plain",
  titlespacer = 3, titleangle = 0, showsubtitle = FALSE,
  subtitlelab = NA, subtitlehjust = 0, subtitlevjust = 0.5,
  subtitlesize = 7, subtitlecol = "grey30", subtitleface = "plain",
  subtitlespacer = 4, subtitleangle = 0, showlegend = FALSE,
  legendlab = NA, legendpos = "right", legendkeysize = 6,
  legendtextsize = 8, legendmargin = c(1, 1, 1, 0), barsize = 0.9,
  barbordersize = 0, barbordercolour = NA, showticks = FALSE,
  showyaxis = FALSE, ticksize = 0.1, ticklength = 0.03,
  outputfilename = NA, imgtype = "png", height = NA, width = NA,
  dpi = 300, units = "cm", mar = c(0.1, 0.5, 0.1, 0.5),
  theme = "theme_grey", basesize = 5, font = "", na.rm = FALSE,
  quiet = FALSE, exportplot = TRUE, returnplot = FALSE,
  returndata = FALSE)

Arguments

qlist

A qlist (list of dataframes). An output from readQ.

spl

An integer indicating samples per line. Defaults to 60.

lpp

An integer indicating lines per page. Defaults to 11.

clustercol

A character vector of colours for clusters.

sortind

A character indicating how individuals are sorted. Default is NA (Same order of individuals as in input file). Other options are 'all' (sorting by values of all clusters), by any one cluster (eg. 'Cluster1') or 'labels' (sorting by individual labels). See details.

grplab

A dataframe with one or more columns (group label sets), and rows equal to the number of individuals. See details.

selgrp

A single character denoting a selected group label set. The selected label must be a group label title used in grplab. See details.

ordergrp

A logical indicating if individuals must be grouped into contiguous blocks based on grplab starting with selgrp.

subsetgrp

A character or character vector with group names to subset or reorder groups. Only applicable when grplab is in use. Default is NA. See details.

grpmean

A logical indicating if q-matrix must be converted from individual values to group mean values. Applicable only when grplab is in use and mean is calculated over selgrp.

showindlab

A logical indicating if individual labels must be shown below the bars. To hide labels, set showindlab=FALSE. See details.

useindlab

A logical indicating if individual labels must be read from the rownames of qlist dataframes and used as labels. See details.

indlabsep

A character used as separator when concatenating individual labels and group labels. Defaults to space indlabsep=" ".

indlabsize

A numeric denoting size of the individual labels. Defaults to 5.

indlabangle

A numeric denoting the angle of the individual labels. Defaults to 90.

indlabvjust

A numeric denoting vertical justification of the individual labels. Defaults to 0.5.

indlabhjust

A numeric denoting the horizontal justification of the individual labels. Defaults to 1.

indlabcol

A colour for individual labels. Defaults to 'grey30'.

indlabspacer

A numeric denoting space between the individual label and the plot area. Default set to 0.

showgrplab

A logical indicating if group labels grplab must be displayed on the plot.

grplabsize

A numeric denoting size of the group labels. Defaults to 7.

grplabcol

A colour for group labels. Defaults to 'grey30'.

grplabbgcol

A colour for group label background. Defaults to 'white'.

titlelab

A character or character vector for title text. Defaults to NA, and when showtitle=TRUE displays file name.

titlehjust

A numeric denoting the horizontal justification of the title. Defaults to 0 (left).

titlevjust

A numeric denoting the vertical justification of the title. Defaults to 0.5 (center).

titlesize

A numeric indicating the size of the title text. Defaults to 5 points.

titlecol

A colour character for title. Defaults to "grey30".

titleface

A character indicating the font face of title label. One of 'plain', 'italic', 'bold' or 'bold.italic'. Defaults to 'plain'. Applicable only when showtitle=T.

titlespacer

A numeric indicating the space below the title. Defaults to 1.2.

titleangle

A numeric indicating the angle/rotation of the title. Defaults to 0.

showsubtitle

A logical indicating if plot subtitle must be shown on the top. Defaults to FALSE. If TRUE and subtitlelab=NA, file name is displayed by default.

subtitlelab

A character or character vector for subtitle text. Defaults to NA, and when showsubtitle=TRUE displays K value like K=2.

subtitlehjust

A numeric denoting the horizontal justification of the subtitle. Defaults to 0 (left).

subtitlevjust

A numeric denoting the vertical justification of the subtitle. Defaults to 0.5 (center).

subtitlesize

A numeric indicating the size of the subtitle text. Defaults to 5 points.

subtitlecol

A colour character for subtitle. Defaults to "grey30".

subtitleface

A character indicating the font face of subtitle label. One of 'plain', 'italic', 'bold' or 'bold.italic'. Defaults to 'plain'. Applicable only when showsubtitle=T.

subtitlespacer

A numeric indicating the space below the subtitle. Defaults to 1.2.

subtitleangle

A numeric indicating the angle/rotation of the subtitle. Defaults to 0.

barsize

A numeric indicating the width of the bars. Defaults to 0.9.

barbordersize

A numeric indicating border size of bars. Defaults to 0. Visible only when barbordercolour is not NA.

barbordercolour

A single colour for bar border. Defaults to NA. Visible only when barbordersize is larger than zero and set to a colour other than NA.

showticks

A logical indicating if ticks on axis should be displayed or not. Defaults to FALSE.

showyaxis

A logical indicating if y-axis labels should be displayed or not. Defaults to FALSE.

outputfilename

A character or character vector denoting output file name without file extension. See details.

imgtype

A character denoting figure output format. Options are 'png', 'jpeg', 'tiff' or 'pdf'.

height

A numeric denoting height of the full figure. If NA, height is set to 29.7cm (A4 height).

width

A numeric denoting width of the full figure. If NA, width is set to 21cm (A4 width).

dpi

A numeric denoting resolution of the figure. Default is 300. If imgtype="pdf", dpi is fixed at 300 and does not have any effect..

units

A character denoting the units of dimension of the figure. Default is "cm". Other options are 'px', 'in' or 'mm'.

mar

A four number vector denoting distance of top, right, bottom and left margins in units.

theme

A character indicating ggplot theme to be used. Use like "theme_grey", "theme_bw" etc.

font

A character indicating font family to be used in the plots. Uses default system fonts by default for jpeg, png and tiff. Uses 'Helvetica' as default for pdf. Use package extrafonts to import custom fonts. See vignette for examples.

na.rm

Default set to FALSE. NAs are not removed from data, therefore ggplot prints warning messages for NAs. If set to TRUE, NAs are removed before plotting and ggplot NA warning is suppressed.

Details

Figures are always created to A4 size. Any plotted row will span the width of the figure. Note that this function is slow and may take several minutes when plotting mutiple runs.

indlab
plotQMultiline() labels each individual separately. When showindlab=T, individual labels are shown/displayed. When showindlab=F, individual labels are not shown/displayed on the graph, although they are present in the underlying data. Therefore, showindlab only control display of labels on the plot and nothing to do with label control in the data.
The default useindlab=F, creates labels numerically in the original order of data but with zero padding. For example, if there are 10 individuals, labels are 01, 02 up to 10. if there are 100 individuals, then labels are 001, 002 up to 100. Zero padding to ensure optimal sorting. When useindlab=T, labels are used from rownames of qlist dataframes. They are usually labelled 1,2,3.. if read in using readQ(). This can be an issue with sorting by labels sortind="label". For STRUCTURE files with individual labels, they can be read in automatically using readQ(indlabfromfile=T).
When group labels are in use, grplab, they are added to the individual labels in both cases useindlab=T and useindlab=F separated by indlabsep. Default indlabsep=" " adds a space between individual label and grplab. For example, group labels 'popA', 'popA'... will be '01 popA', '02 popA'... when useindlab=F and usually '1 popA', '2 popA'... when useindlab=T. When multiple group labels are in use, the are similarly concatenated one after the other to individual names in the order in which the group labels were provided.

sortind
This argument takes one character as input. Default NA means individuals are plotted in the same order as input. Individuals can be ordered by any one cluster. For ex. sortind="Cluster1" or sortind="Cluster2". To order by all clusters as the 'Sort by Q' option in STRUCTURE software, use sortind="all". To order by individual labels, use sortind="label". When using sortind with grplab, individuals are sorted within the groups.

grplab
grplab must be a list. One or more label sets can be provided. Each label set must be a character vector equal to the number of individuals present in the qlist. For example, we can provide one set of grp labels as such:
labs1 <- c("Grp A","Grp A","Grp B","Grp B")
grplab=list("grp"=labs1)

A second set of grp labels can be provided as such: labs2 <- c("Loc 1","Loc 1","Loc 2","Loc 3")
grplab=list("population"=labs1,"location"=labs2)

subsetgrp
This argument takes one or more characters as input. Use only group labels exactly as used in the grplab vector. For ex. In case of two grps in order 'Pop A' and 'Pop B', use subsetgrp=c("Pop B","Pop A") to change order of groups. Use subsetgrp="Pop B" to subset only Pop B.

outputfilename
Output file names are created automatically by default using the input qlist names. When number of individuals exceed one page and extra pages are created, incremental numbers are added to the run name like so: -1, -2 etc. Custom file name can be provided to outputfilename. The number of labels must be equal to the number of input runs. Incremental numbers are still added if extra pages are created.

See the vignette for more details.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
## Not run: 
sfiles <- list.files(path=system.file("files/structure",package="pophelper"),full.names=TRUE)
slist <- readQ(sfiles)

# basic
plotQMultiline(slist[1])

# multiple files
plotQMultiline(slist[1:3])

# adjust samples per line (spl) and lines per page (lpp)
plotQMultiline(slist[1],spl=30)
plotQMultiline(slist[1],lpp=8)
plotQMultiline(slist[1],spl=75,lpp=10)

# sort individuals
plotQMultiline(slist[1],sortind="all")
plotQMultiline(slist[1],sortind="Cluster1")
plotQMultiline(slist[1],sortind="label")

# use custom individual labels
inds <- read.delim(system.file("files/structureindlabels.txt",package="pophelper"),header=FALSE,stringsAsFactors=FALSE)
rownames(slist[[1]]) <- inds$V1
plotQMultiline(slist[1],useindlab=T)

# change cluster colours
plotQMultiline(slist[1],clustercol=c("steelblue","coral"))

# change bar width and height
plotQMultiline(slist[1],barsize=1,spl=149,indlabsize=3,height=5)

# read group labels
md <- read.delim(system.file("files/metadata.txt", package="pophelper"), header=T,stringsAsFactors=F)

# plot with one group label set
plotQMultiline(qlist=slist[1],grplab=md[,2,drop=F])
plotQMultiline(qlist=slist[1],grplab=md[,2,drop=F],useindlab=T)

# sort ind within groups
plotQMultiline(qlist=slist[1],grplab=md[,2,drop=F],sortind="Cluster1")
plotQMultiline(qlist=slist[1],grplab=md[,2,drop=F],sortind="all")
plotQMultiline(qlist=slist[1],grplab=md[,2,drop=F],sortind="label")

# subset or reorder groups
plotQMultiline(qlist=slist[1],grplab=md[,2,drop=F],subsetgrp=c("CatB"))
plotQMultiline(qlist=slist[1],grplab=md[,2,drop=F],subsetgrp=c("Cat B","CatA"))

# using multiple group label sets
plotQMultiline(qlist=slist[1],grplab=md,ordergrp=TRUE)

# subset on a group from second group label set
plotQMultiline(qlist=slist[1],grplab=md,selgrp="cat",subsetgrp="CatB")


## End(Not run)

royfrancis/pophelper documentation built on Aug. 21, 2018, 4:48 a.m.