Skip to content
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ Authors@R: person(given = "Aaron",
Description: Functions to make useful (and pretty) plots for scientific plotting. Additional plotting features are added for base plotting, with particular emphasis on making attractive log axis plots.
License: LGPL-3
Suggests: imager, fst, plotly, abind
Imports: grDevices, graphics, stats, celestial (>= 1.4.1), MASS, plotrix, sm, mapproj, RANN
Imports: grDevices, graphics, stats, celestial (>= 1.4.1), MASS, plotrix, sm, mapproj, RANN, ParmOff
Remotes: asgr/ParmOff
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ importFrom("plotrix", "color.legend", "draw.ellipse")
importFrom("sm", "sm.density")
importFrom("MASS", "kde2d")
importFrom("utils", "str")
importFrom("ParmOff", "ParmOff")
16 changes: 8 additions & 8 deletions R/magaxis.R
Original file line number Diff line number Diff line change
Expand Up @@ -156,26 +156,26 @@ for(i in 1:length(side)){
}

if(logged){
do.call("axis", c(list(side=currentside,at=powbase^major.ticks,tcl=tcl,labels=FALSE,tick=do.tick,mgp=mgp,lwd=axis.lwd,lwd.ticks=ticks.lwd,col=axis.col),dotsaxis))
ParmOff(axis, c(list(side=currentside,at=powbase^major.ticks,tcl=tcl,labels=FALSE,tick=do.tick,mgp=mgp,lwd=axis.lwd,lwd.ticks=ticks.lwd,col=axis.col),dotsaxis))
}else{
do.call("axis", c(list(side=currentside,at=major.ticks,tcl=tcl,labels=FALSE,tick=do.tick,mgp=mgp,lwd=axis.lwd,lwd.ticks=ticks.lwd,col=axis.col),dotsaxis))
ParmOff(axis, c(list(side=currentside,at=major.ticks,tcl=tcl,labels=FALSE,tick=do.tick,mgp=mgp,lwd=axis.lwd,lwd.ticks=ticks.lwd,col=axis.col),dotsaxis))
}

if(labels){
if(logged){
do.call("axis", c(list(side=currentside,at=powbase^labloc,tick=F,labels=uselabels,mgp=mgp,lwd=axis.lwd,lwd.ticks=ticks.lwd,col=axis.col),dotsaxis))
ParmOff(axis, c(list(side=currentside,at=powbase^labloc,tick=F,labels=uselabels,mgp=mgp,lwd=axis.lwd,lwd.ticks=ticks.lwd,col=axis.col),dotsaxis))
}else{
do.call("axis", c(list(side=currentside,at=labloc,tick=F,labels=uselabels,mgp=mgp,lwd=axis.lwd,lwd.ticks=ticks.lwd,col=axis.col),dotsaxis))
ParmOff(axis, c(list(side=currentside,at=labloc,tick=F,labels=uselabels,mgp=mgp,lwd=axis.lwd,lwd.ticks=ticks.lwd,col=axis.col),dotsaxis))
}
}

if(usemultloc==F & minorn>1){
minors = minors[-c(1,length(minors))]
minor.ticks = c(outer(minors, major.ticks, `+`))
if(logged){
do.call("axis", c(list(side=currentside,at=powbase^minor.ticks,tcl=tcl*ratio,labels=FALSE,tick=do.tick,mgp=mgp,lwd=axis.lwd,lwd.ticks=ticks.lwd,col=axis.col),dotsaxis))
ParmOff(axis, c(list(side=currentside,at=powbase^minor.ticks,tcl=tcl*ratio,labels=FALSE,tick=do.tick,mgp=mgp,lwd=axis.lwd,lwd.ticks=ticks.lwd,col=axis.col),dotsaxis))
}else{
do.call("axis", c(list(side=currentside,at=minor.ticks,tcl=tcl*ratio,labels=FALSE,tick=do.tick,mgp=mgp,lwd=axis.lwd,lwd.ticks=ticks.lwd,col=axis.col),dotsaxis))
ParmOff(axis, c(list(side=currentside,at=minor.ticks,tcl=tcl*ratio,labels=FALSE,tick=do.tick,mgp=mgp,lwd=axis.lwd,lwd.ticks=ticks.lwd,col=axis.col),dotsaxis))
}
}
}
Expand All @@ -184,10 +184,10 @@ for(i in 1:length(side)){
names(dotsmtext)=c('cex', 'col', 'font')[match(names(dotsmtext), dotskeepmtext)]
}
if(is.null(xlab)==FALSE){
do.call("mtext", c(list(text=xlab, side=ifelse(side[1] %in% c(1,3), side[1], side[2]), line=mtline[1]), dotsmtext))
ParmOff(mtext, c(list(text=xlab, side=ifelse(side[1] %in% c(1,3), side[1], side[2]), line=mtline[1]), dotsmtext))
}
if(is.null(ylab)==FALSE){
do.call("mtext", c(list(text=ylab, side=ifelse(side[2] %in% c(2,4), side[2], side[1]), line=mtline[2]), dotsmtext))
ParmOff(mtext, c(list(text=ylab, side=ifelse(side[2] %in% c(2,4), side[2], side[1]), line=mtline[2]), dotsmtext))
}

if(frame.plot){box()}
Expand Down
12 changes: 6 additions & 6 deletions R/magbin.R
Original file line number Diff line number Diff line change
Expand Up @@ -304,11 +304,11 @@ plot.magbin = function(x, colramp=hcl.colors(21), colstretch='lin', sizestretch=
if(!is.na(x$dustlim)){
x$bins = x$bins[x$bins[,'count']>x$dustlim,]
}
colmap = do.call("magmap", c(list(data=x$bins[,colref], stretch=colstretch, range=c(1,length(colramp)), bad=NA), dotsmap))
colmap = ParmOff(magmap, c(list(data=x$bins[,colref], stretch=colstretch, range=c(1,length(colramp)), bad=NA), dotsmap))
if(sizeref=='none'){
sizemap = rep(1,dim(x$bins)[1])
}else{
sizemap = do.call("magmap", c(list(data=x$bins[,sizeref], stretch=sizestretch, range=c(0,1), bad=NA)))$map
sizemap = ParmOff(magmap, c(list(data=x$bins[,sizeref], stretch=sizestretch, range=c(0,1), bad=NA)))$map
}
#colmap = magmap(x$bins[,3], stretch=stretch, bad=NA, range=c(1,length(colramp)))
if('xlim' %in% names(dots)){
Expand Down Expand Up @@ -351,9 +351,9 @@ plot.magbin = function(x, colramp=hcl.colors(21), colstretch='lin', sizestretch=

#4 (bottomright)
par(mar=c(0,0,0,0))
do.call("magplot", c(list(NA, NA, xlim=xlim, ylim=ylim, side=c(1,2,3,4), labels=c(T,T,F,F)), dots))
ParmOff(magplot, c(list(NA, NA, xlim=xlim, ylim=ylim, side=c(1,2,3,4), labels=c(T,T,F,F)), dots))
}else{
do.call("magplot", c(list(NA, NA, xlim=xlim, ylim=ylim), dots))
ParmOff(magplot, c(list(NA, NA, xlim=xlim, ylim=ylim), dots))
}
}
#magplot(NA, NA, xlim=x$xlim, ylim=x$ylim, ...)
Expand Down Expand Up @@ -387,7 +387,7 @@ plot.magbin = function(x, colramp=hcl.colors(21), colstretch='lin', sizestretch=
points(x$dust$x, x$dust$y, pch=pch.dust, col=colramp[1], cex=cex.dust)
}else{
if(colref=='zstat'){
colmapdust = do.call("magmap", c(list(data=x$dust$z, locut=colmap$datalim[1],
colmapdust = ParmOff(magmap, c(list(data=x$dust$z, locut=colmap$datalim[1],
hicut=colmap$datalim[2], type='num', stretch=colstretch,
range=c(1,length(colramp)), bad=NA)))$map
points(x$dust$x, x$dust$y, pch=pch.dust, col=colramp[colmapdust], cex=cex.dust)
Expand All @@ -404,7 +404,7 @@ plot.magbin = function(x, colramp=hcl.colors(21), colstretch='lin', sizestretch=
title = "norm"
}
}
do.call("magbar", c(list(range=colmap$datalim, log=colstretch=='log', col=colramp, title=title), dotsbar))
ParmOff(magbar, c(list(range=colmap$datalim, log=colstretch=='log', col=colramp, title=title), dotsbar))
}
}

Expand Down
2 changes: 1 addition & 1 deletion R/magimage.R
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ magimage = function(x, y, z, zlim, xlim, ylim, col = grey((0:1e3)/1e3), add = FA
}
}

do.call('image',c(list(x=x, y=y, z=z, zlim=zlim, xlim=xlim, ylim=ylim, col=col, add=add, useRaster=useRaster, axes=FALSE, asp=asp, xlab='', ylab='', main=''), dotsimage))
ParmOff(image,c(list(x=x, y=y, z=z, zlim=zlim, xlim=xlim, ylim=ylim, col=col, add=add, useRaster=useRaster, axes=FALSE, asp=asp, xlab='', ylab='', main=''), dotsimage))

if(add==FALSE){
if(axes){
Expand Down
2 changes: 1 addition & 1 deletion R/magimageRGB.R
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ magimageRGB<-function(x, y, R, G, B, saturation=1, zlim, xlim, ylim, add = FALSE
z = matrix(1:length(R),dim(R)[1])
col = rgb(R,G,B)

do.call('image',c(list(x=x, y=y, z=z, zlim=zlim, xlim=xlim, ylim=ylim, col=col, add=add, useRaster=useRaster, axes=FALSE, asp=asp, xlab='', ylab='', main=''), dotsimage))
ParmOff(image,c(list(x=x, y=y, z=z, zlim=zlim, xlim=xlim, ylim=ylim, col=col, add=add, useRaster=useRaster, axes=FALSE, asp=asp, xlab='', ylab='', main=''), dotsimage))
if(add==FALSE){
if(axes){
magaxis(...)
Expand Down
8 changes: 4 additions & 4 deletions R/magplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ magplot =
...) {
if (class(x)[1] == 'histogram') {
dots = list(...)
do.call('maghist', c(
ParmOff(maghist, c(
list(
x = x,
xlim = xlim,
Expand Down Expand Up @@ -264,7 +264,7 @@ magplot =
zstretch = 'log'
}
}
colmap = do.call("magmap", c(
colmap = ParmOff(magmap, c(
list(
data = z,
stretch = zstretch,
Expand Down Expand Up @@ -317,11 +317,11 @@ magplot =
xlim = xlim,
ylim = ylim
)
do.call("points", c(list(
ParmOff(points, c(list(
x = x, y = y, col = zcol[colmap$map]
), dots))
if (dobar) {
do.call("magbar", c(
ParmOff(magbar, c(
list(
range = colmap$datalim,
log = zstretch == 'log',
Expand Down
32 changes: 17 additions & 15 deletions R/magtri.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ magtri=function(chains, samples=1000, thin=1, samptype='end', grid=FALSE, do.tic
}
if(Npar<=1){stop('Need 2+ parameters!')}

dots=list(...)

if(thin>1){
chains=chains[seq(1,Nsamp,by=thin),,drop=FALSE]
Nsamp=dim(chains)[1]
Expand Down Expand Up @@ -44,7 +46,7 @@ magtri=function(chains, samples=1000, thin=1, samptype='end', grid=FALSE, do.tic
xtemp=chains[usesamps,i]
if(sd(xtemp)==0){xtemp=xtemp+rnorm(samples,sd=1e-3)}
plot(density(xtemp),axes=FALSE,main='',xlim=xrange)
magaxis(1,grid=grid, grid.col = 'lightgrey',labels=FALSE,do.tick=do.tick)
ParmOff(magaxis, dots, side=1, grid=grid, grid.col='lightgrey', labels=FALSE, do.tick=do.tick)
abline(v=meanvec[i],lty=1,col='red')
abline(v=meanvec[i]-sdvec[i],lty=3,col='red')
abline(v=meanvec[i]+sdvec[i],lty=3,col='red')
Expand All @@ -55,14 +57,14 @@ magtri=function(chains, samples=1000, thin=1, samptype='end', grid=FALSE, do.tic
if(i==1){
plot.window(xlim=xrange,ylim=yrange)
if(is.null(lab)){
magaxis(1,xlab=chaincolnames[i])
ParmOff(magaxis, dots, side=1, xlab=chaincolnames[i])
}else{
magaxis(1,xlab=lab[[i]])
ParmOff(magaxis, dots, side=1, xlab=lab[[i]])
}
if(is.null(lab)){
magaxis(2,ylab=chaincolnames[j])
ParmOff(magaxis, dots, side=2, ylab=chaincolnames[j])
}else{
magaxis(2,ylab=lab[[j]])
ParmOff(magaxis, dots, side=2, ylab=lab[[j]])
}
}
}else{
Expand All @@ -73,9 +75,9 @@ magtri=function(chains, samples=1000, thin=1, samptype='end', grid=FALSE, do.tic
ytemp=chains[usesamps,j]
if(sd(xtemp)==0){xtemp=xtemp+rnorm(samples,sd=1e-3)}
if(sd(ytemp)==0){ytemp=ytemp+rnorm(samples,sd=1e-3)}
magaxis(1:2,grid=grid, grid.col = 'lightgrey',labels=FALSE,do.tick=do.tick)
magcon(xtemp,ytemp,dobar=FALSE,doim=FALSE,add=TRUE,lty=c(2,1,3),xlim=xrange,ylim=yrange, h=c(diff(xrange),diff(yrange))/10, ...)
points(meanvec[i],meanvec[j],col='red',pch=4,cex=2)
ParmOff(magaxis, dots, side=1:2, grid=grid, grid.col='lightgrey', labels=FALSE, do.tick=do.tick)
ParmOff(magcon, dots, x=xtemp, y=ytemp, dobar=FALSE, doim=FALSE, add=TRUE, lty=c(2,1,3), xlim=xrange, ylim=yrange, h=c(diff(xrange),diff(yrange))/10)
ParmOff(points, dots, x=meanvec[i], y=meanvec[j], col='red', pch=4, cex=2)
box()
abline(v=meanvec[i],lty=1,col='red')
abline(v=meanvec[i]-sdvec[i],lty=3,col='red')
Expand All @@ -85,23 +87,23 @@ magtri=function(chains, samples=1000, thin=1, samptype='end', grid=FALSE, do.tic
}
if(j==1){
if(is.null(lab)){
magaxis(1,xlab=chaincolnames[i])
ParmOff(magaxis, dots, side=1, xlab=chaincolnames[i])
}else{
magaxis(1,xlab=lab[[i]])
ParmOff(magaxis, dots, side=1, xlab=lab[[i]])
}
}
}else{
plot.new()
plot.window(xlim=xrange,ylim=yrange)
magaxis(1:2,grid=grid, grid.col = 'lightgrey',labels=FALSE,do.tick=do.tick)
points(chains[usesamps,c(i,j)],pch='.',col='darkgrey')
points(meanvec[i],meanvec[j],col='red',pch=4,cex=2)
ParmOff(magaxis, dots, side=1:2, grid=grid, grid.col='lightgrey', labels=FALSE, do.tick=do.tick)
ParmOff(points, dots, x=chains[usesamps,i], y=chains[usesamps,j], pch='.', col='darkgrey')
ParmOff(points, dots, x=meanvec[i], y=meanvec[j], col='red', pch=4, cex=2)
box()
if(i==1){
if(is.null(lab)){
magaxis(2,ylab=chaincolnames[j])
ParmOff(magaxis, dots, side=2, ylab=chaincolnames[j])
}else{
magaxis(2,ylab=lab[[j]])
ParmOff(magaxis, dots, side=2, ylab=lab[[j]])
}
}
}
Expand Down