Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,4 @@ po/*~

# RStudio Connect folder
rsconnect/
.positai
11 changes: 7 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
Package: magicaxis
Type: Package
Title: Pretty Scientific Plotting with Minor-Tick and Log Minor-Tick Support
Version: 2.5.3
Date: 2025-02-24
Version: 2.6.0
Date: 2026-05-14
Authors@R: person(given = "Aaron",
family = "Robotham",
role = c("aut", "cre"),
email = "aaron.robotham@uwa.edu.au")
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
Suggests: imager, fst, plotly, abind, testthat (>= 3.0.0), knitr, rmarkdown
Imports: grDevices, graphics, stats, celestial (>= 1.4.1), MASS, plotrix, sm, mapproj, RANN, ParmOff
Remotes: asgr/ParmOff
VignetteBuilder: knitr
Config/testthat/edition: 3
3 changes: 2 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import("mapproj")
importFrom("grDevices", "hsv", "rainbow", "grey", "rgb", "dev.cur", "extendrange", "colorRampPalette", "hcl.colors", "grey.colors")
importFrom("graphics", "arrows", "axis", "box", "contour", "image", "mtext", "par",
"plot", "plot.new", "plot.window", "rect", "text", "abline", "layout",
"lines", "points", "polygon", "hist")
"lines", "points", "points.default", "polygon", "hist")
importFrom("stats", "approxfun", "density", "median", "pnorm", "quantile", "sd", "rnorm", "ecdf", "qnorm", "mad", "aggregate", "runif")
importFrom("celestial", "hms2deg", "dms2deg", "deg2hms", "deg2dms", "radec2xy", "xy2radec", "getpixscale")
importFrom("RANN", "nn2")
importFrom("plotrix", "color.legend", "draw.ellipse")
importFrom("sm", "sm.density")
importFrom("MASS", "kde2d")
importFrom("utils", "str")
importFrom("ParmOff", "ParmOff")
30 changes: 10 additions & 20 deletions R/magaxis.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,8 @@ function(side=1:2, majorn=5, minorn='auto', tcl=0.5, ratio=0.5, labels=TRUE, unl
usepar=FALSE, grid=FALSE, grid.col='grey', grid.lty=1, grid.lwd=1, axis.lwd=1,
ticks.lwd=axis.lwd, axis.col='black', do.tick=TRUE, ...){
dots=list(...)
dotskeepaxis=c('cex.axis', 'col.axis', 'font.axis', 'xaxp', 'yaxp', 'tck', 'las', 'fg', 'xpd', 'xaxt', 'yaxt', 'col.ticks')
dotskeepmtext=c('cex.lab', 'col.lab', 'font.lab')
if(length(dots)>0){
dotsaxis=dots[names(dots) %in% dotskeepaxis]
dotsmtext=dots[names(dots) %in% dotskeepmtext]
}else{
dotsaxis={}
dotsmtext={}
}
keepaxis = c('side', 'at', 'tcl', 'labels', 'tick', 'mgp', 'lwd', 'lwd.ticks', 'col', 'cex.axis', 'col.axis', 'font.axis', 'xaxp', 'yaxp', 'tck', 'las', 'fg', 'xpd', 'xaxt', 'yaxt', 'col.ticks')
keepmtext = c('text', 'side', 'line', 'cex.lab', 'col.lab', 'font.lab')
if(length(mtline)==1){mtline=rep(mtline,2)}
majornlist=majorn
minornlist=minorn
Expand Down Expand Up @@ -156,38 +149,35 @@ 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),dots), .use_args=keepaxis)
}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),dots), .use_args=keepaxis)
}

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),dots), .use_args=keepaxis)
}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),dots), .use_args=keepaxis)
}
}

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), dots),.use_args=keepaxis)
}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),dots), .use_args=keepaxis)
}
}
}

if(length(dotsmtext)>0){
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]), dots), .use_args = keepmtext)
}
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]), dots), .use_args = keepmtext)
Comment on lines +177 to +180
}

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/magcon.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function(x,y,h,doim=TRUE,docon=TRUE,dobar=TRUE,ngrid=100,add=FALSE,xlab='',ylab=
usrlims=par()$usr
rect(usrlims[1],usrlims[3],usrlims[2],usrlims[4],col=imcol[1])
}
magimage(tempcon,col=imcol,axes=FALSE,add=TRUE,xlim=xlim,ylim=ylim,magmap=FALSE)
magimage(tempcon[c('x', 'y', 'z')],col=imcol,axes=FALSE,add=TRUE,xlim=xlim,ylim=ylim,magmap=FALSE)
}
if(doim & docon){contour(tempcon,levels=conlevels,add=TRUE,drawlabels=F,axes=FALSE,...)}
if(doim==FALSE & docon){contour(tempcon,levels=conlevels,add=add,drawlabels=F,axes=FALSE,xlim=xlim,ylim=ylim,...);box()}
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
14 changes: 6 additions & 8 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 @@ -121,8 +121,7 @@ magplot =
grid.lwd = grid.lwd,
axis.lwd = axis.lwd,
ticks.lwd = ticks.lwd,
axis.col = axis.col,
...
axis.col = axis.col
)
},
lwd = lwd,
Expand Down Expand Up @@ -220,8 +219,7 @@ magplot =
grid.lwd = grid.lwd,
axis.lwd = axis.lwd,
ticks.lwd = ticks.lwd,
axis.col = axis.col,
...
axis.col = axis.col
)
},
lwd = lwd,
Expand Down Expand Up @@ -264,7 +262,7 @@ magplot =
zstretch = 'log'
}
}
colmap = do.call("magmap", c(
colmap = ParmOff(magmap, c(
list(
data = z,
stretch = zstretch,
Expand Down Expand Up @@ -317,11 +315,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, .pass_dots=FALSE)
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], .pass_dots=FALSE)
}else{
magaxis(1,xlab=lab[[i]])
ParmOff(magaxis, dots, side=1, xlab=lab[[i]], .pass_dots=FALSE)
}
if(is.null(lab)){
magaxis(2,ylab=chaincolnames[j])
ParmOff(magaxis, dots, side=2, ylab=chaincolnames[j], .pass_dots=FALSE)
}else{
magaxis(2,ylab=lab[[j]])
ParmOff(magaxis, dots, side=2, ylab=lab[[j]], .pass_dots=FALSE)
}
}
}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, .pass_dots=FALSE)
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, .pass_dots=FALSE)
ParmOff(points, dots, x=meanvec[i], y=meanvec[j], col='red', pch=4, cex=2, .pass_dots=FALSE)
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], .pass_dots=FALSE)
}else{
magaxis(1,xlab=lab[[i]])
ParmOff(magaxis, dots, side=1, xlab=lab[[i]], .pass_dots=FALSE)
}
}
}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)
dots_carry = ParmOff(magaxis, dots, side=1:2, grid=grid, grid.col='lightgrey', labels=FALSE, do.tick=do.tick, .pass_dots=FALSE, .return='func_args')$args_out$ignore_args
ParmOff(points.default, dots_carry, x=chains[usesamps,i], y=chains[usesamps,j], pch='.', col='darkgrey', .pass_dots=TRUE)
ParmOff(points.default, dots_carry, x=meanvec[i], y=meanvec[j], col='red', pch=4, cex=2, .pass_dots=TRUE)
Comment on lines +98 to +100
box()
if(i==1){
if(is.null(lab)){
magaxis(2,ylab=chaincolnames[j])
ParmOff(magaxis, dots, side=2, ylab=chaincolnames[j], .pass_dots=FALSE)
}else{
magaxis(2,ylab=lab[[j]])
ParmOff(magaxis, dots, side=2, ylab=lab[[j]], .pass_dots=FALSE)
}
}
}
Expand Down
1 change: 0 additions & 1 deletion man/magaxis.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ magaxis(side=c(1,3),unlog=c(TRUE,FALSE))

plot(x,y,axes=FALSE,log='x')
magaxis()

}

% Add one or more standard keywords, see file 'KEYWORDS' in the
Expand Down
1 change: 0 additions & 1 deletion man/magmap.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ stretch='asinh')$map
magplot(datastretch[,1],datastretch[,3],side=1)
axis(2,asinhticks,labels=c(-10^(4:0),0,10^(0:4)))
abline(h=magmap(0,lo=-1e4,hi=1e4,range=c(0,1),type='num',stretch='asinh')$map)

}
% Add one or more standard keywords, see file 'KEYWORDS' in the
% R documentation directory.
Expand Down
4 changes: 4 additions & 0 deletions tests/testthat.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
library(testthat)
library(magicaxis)

test_check("magicaxis")
Loading
Loading