-
Notifications
You must be signed in to change notification settings - Fork 7
/
PlotQ.R
67 lines (57 loc) · 2.49 KB
/
PlotQ.R
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
56
57
58
59
60
61
62
63
64
65
66
source('Colors.R', chdir = TRUE)
#create a bar plot from data that has been read in
### THERE ARE INCOMPLETE PARTS OF THIS SCRIPT, currently working with clumpp files, but other applications not quite ready
plot.bars <- function(bars, wid=1, sp=0, title="", bord=NA, color=colors, ax.lab=TRUE, outfile=NULL, type=c("quartz","pdf","tiff","png","jpeg"), wd=width, ht=height)
{
#if(is.null(outfile)){
if(type=="quartz"){
quartz()
par(fig=c(0,1,0,1),mar=c(2,2,1,1),oma=c(1,0.5,0.5,0.5),xaxs="i",yaxs="i",bg=NA)
barplot(bars, width=wid, space=sp, names.arg=rep("",ncol(bars)), col=color, border=bord, main=title)
#having things like "border=border" creates a recursive error
par(lwd=1)
par(new=T)
barplot(popsizes/popsizes, width=popsizes, space=sp, col=NA, axisnames=ax.lab)
}
#plot to an output file if outfile gives a file path
path <- outfile
type <- if (!missing(type))
match.arg(type)
if(type=="pdf"){
pdf(sprintf(path), width=wd, height=ht)
par(fig=c(0,1,0,1),mar=c(2,2,1,1),oma=c(1,0.5,0.5,0.5),xaxs="i",yaxs="i",bg=NA)
barplot(bars, width=wid, space=sp, names.arg=rep("",ncol(bars)), col=color, border=bord, main=title)
par(lwd=1)
par(new=T)
barplot(popsizes/popsizes, width=popsizes, space=sp, col=NA, axisnames=ax.lab)
dev.off()
}
if(type=="tiff"){
tiff(sprintf(path), compression="none", units="px", width=wd, height=ht, res=100, antialias="none")
par(fig=c(0,1,0,1),mar=c(2,2,1,1),oma=c(1,0.5,0.5,0.5),xaxs="i",yaxs="i",bg=NA)
barplot(bars, width=wid, space=sp, names.arg=rep("",ncol(bars)), col=color, border=bord, main=title)
par(lwd=1)
par(new=T)
barplot(popsizes/popsizes, width=popsizes, space=sp, col=NA, axisnames=ax.lab)
dev.off()
}
if(type=="png"){
png(sprintf(path), width=wd, height=ht)
par(fig=c(0,1,0,1),mar=c(2,2,1,1),oma=c(1,0.5,0.5,0.5),xaxs="i",yaxs="i",bg=NA)
barplot(bars, width=wid, space=sp, names.arg=rep("",ncol(bars)), col=color, border=bord, main=title)
par(lwd=1)
par(new=T)
barplot(popsizes/popsizes, width=popsizes, space=sp, col=NA, axisnames=ax.lab)
dev.off()
}
if(type=="jpeg"){
jpeg(sprintf(path), width=wd, height=ht, quality=100)
par(fig=c(0,1,0,1),mar=c(2,2,1,1),oma=c(1,0.5,0.5,0.5),xaxs="i",yaxs="i",bg=NA)
barplot(bars, width=wid, space=sp, names.arg=rep("",ncol(bars)), col=color, border=bord, main=title)
par(lwd=1)
par(new=T)
barplot(popsizes/popsizes, width=popsizes, space=sp, col=NA, axisnames=ax.lab)
dev.off()
}
}
#remove x axis labels by saying 'ax.lab=FALSE' when running plot.bars function