Skip to content

Commit d8abaae

Browse files
committed
Better interactive things. Now magimageRGB is working!
1 parent 8aa3830 commit d8abaae

6 files changed

Lines changed: 39 additions & 178 deletions

File tree

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ Authors@R: person(given = "Aaron",
99
email = "aaron.robotham@uwa.edu.au")
1010
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.
1111
License: GPL-3
12-
Suggests: imager, fst, plotly
12+
Suggests: imager, fst, plotly, abind
1313
Imports: grDevices, graphics, stats, celestial (>= 1.4.1), MASS, plotrix, sm, mapproj, RANN

R/magerr.R

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,25 @@ magerr = function(x, y, xlo, ylo, xhi=xlo, yhi=ylo, corxy, length=0.02, col='bla
4848
if(!missing(ylo) | !missing(yhi)){yhidraw=y+abs(yhi);doyhi=TRUE}else{yhidraw=0;doyhi=FALSE}
4949

5050
if(doxlo & par()$xlog){
51-
sel=which(xlodraw<=0)
52-
xlodraw[sel]=1e-300
51+
sel = which(xlodraw <= 0)
52+
xlodraw[sel] = 1e-300
5353
}
54-
if(doxhi & par()$xlog){
55-
sel=which(xhidraw>0 & x<=0)
56-
x[sel]=1e-300
54+
if (doxhi & par()$xlog){
55+
sel = which(xhidraw > 0 & x <= 0)
56+
x[sel] = 1e-300
57+
sel = which(xhidraw < 0)
58+
xhidraw[sel] = 1e-300
5759
}
58-
if(doylo & par()$ylog){
59-
sel=which(ylodraw<=0)
60-
ylodraw[sel]=1e-300
60+
if (doylo & par()$ylog){
61+
sel = which(ylodraw <= 0)
62+
ylodraw[sel] = 1e-300
6163
}
62-
if(doyhi & par()$ylog){
63-
sel=which(yhidraw>0 & y<=0)
64-
y[sel]=1e-300
64+
if (doyhi & par()$ylog){
65+
sel = which(yhidraw > 0 & y <= 0)
66+
y[sel] = 1e-300
67+
sel = which(yhidraw < 0)
68+
yhidraw[sel] = 1e-300
69+
#Fix this!
6570
}
6671

6772
xarrow=x[errbarsel]

R/magimageRGB.R

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ magimageRGB<-function(x, y, R, G, B, saturation=1, zlim, xlim, ylim, add = FALSE
22
useRaster=TRUE, asp=1, magmap=TRUE, locut=0.4, hicut=0.995,
33
flip=FALSE, range=c(0,1), type = "quan", stretch="asinh",
44
stretchscale='auto', bad=range[1], clip="", axes=TRUE, frame.plot=TRUE,
5-
sparse='auto', ...){
5+
sparse='auto', interact=FALSE, ...){
66
dots=list(...)
77
dotskeepimage=c('xaxs', 'yaxs', 'breaks', 'oldstyle')
88
if(length(dots)>0){
@@ -88,25 +88,28 @@ magimageRGB<-function(x, y, R, G, B, saturation=1, zlim, xlim, ylim, add = FALSE
8888
rm(Ba)
8989
}
9090

91+
if(interact){
92+
if(!requireNamespace("plotly", quietly = TRUE)){
93+
stop('The plotly package is needed for this function to work. Please install it from CRAN.', call. = FALSE)
94+
}
95+
if(!requireNamespace("abind", quietly = TRUE)){
96+
stop('The abind package is needed for this function to work. Please install it from CRAN.', call. = FALSE)
97+
}
98+
fig = plotly::plot_ly(z=abind::abind(t(R*256), t(G*256), t(B*256), along=3), type = "image")
99+
100+
fig = plotly::layout(
101+
p = fig,
102+
xaxis = list(range = xlim, scaleanchor = "y"), # Set x-axis limits and anchor to y-axis
103+
yaxis = list(range = ylim) # Set y-axis limits
104+
)
105+
106+
print(fig)
107+
return(invisible(NULL))
108+
}
109+
91110
z = matrix(1:length(R),dim(R)[1])
92111
col = rgb(R,G,B)
93112

94-
# if(interact){
95-
# if(!requireNamespace("plotly", quietly = TRUE)){
96-
# stop('The plotly package is needed for this function to work. Please install it from CRAN.', call. = FALSE)
97-
# }
98-
# fig = plotly::plot_ly(x=x, y=y, z=z, type = "heatmap", colors = col, transpose=TRUE)
99-
#
100-
# fig = plotly::layout(
101-
# p = fig,
102-
# xaxis = list(range = xlim, scaleanchor = "y"), # Set x-axis limits and anchor to y-axis
103-
# yaxis = list(range = ylim) # Set y-axis limits
104-
# )
105-
#
106-
# print(fig)
107-
# return(invisible(NULL))
108-
# }
109-
110113
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))
111114
if(add==FALSE){
112115
if(axes){

README.Rmd

Lines changed: 0 additions & 145 deletions
This file was deleted.

README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
2-
<!-- README.md is generated from README.Rmd. Please edit that file -->
3-
41
# magicaxis
52

63
<!-- badges: start -->

man/magimage.Rd

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ magimage(x, y, z, zlim, xlim, ylim, col = grey((0:1000)/1000), add = FALSE,
1818
magimageRGB(x, y, R, G, B, saturation = 1, zlim, xlim, ylim, add = FALSE,
1919
useRaster = TRUE, asp = 1, magmap = TRUE, locut = 0.4, hicut = 0.995, flip = FALSE,
2020
range = c(0, 1), type = "quan", stretch = "asinh", stretchscale = "auto",
21-
bad = range[1], clip = "", axes = TRUE, frame.plot = TRUE, sparse = 'auto', ...)
21+
bad = range[1], clip = "", axes = TRUE, frame.plot = TRUE, sparse = 'auto',
22+
interact = FALSE, ...)
2223
}
2324
%- maybe also 'usage' for other objects documented here.
2425
\arguments{

0 commit comments

Comments
 (0)