Skip to content

Commit 8aa3830

Browse files
committed
plotly interactive stuff added to magimage
1 parent 403c618 commit 8aa3830

5 files changed

Lines changed: 45 additions & 13 deletions

File tree

DESCRIPTION

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
Package: magicaxis
22
Type: Package
33
Title: Pretty Scientific Plotting with Minor-Tick and Log Minor-Tick Support
4-
Version: 2.5.1
5-
Date: 2025-08-04
4+
Version: 2.5.2
5+
Date: 2025-09-18
66
Authors@R: person(given = "Aaron",
77
family = "Robotham",
88
role = c("aut", "cre"),
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
12+
Suggests: imager, fst, plotly
1313
Imports: grDevices, graphics, stats, celestial (>= 1.4.1), MASS, plotrix, sm, mapproj, RANN

R/magbin.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@
304304
}
305305

306306
output = list(bins=data.frame(grid, count=bincount, zstat=binzstat), dust=dust, groups=groups,
307-
xlim=xlim, ylim=ylim, step=step, dustlim=dustlim, shape=shape, direction=direction)
307+
xlim=xlim, ylim=ylim, step=step, dustlim=dustlim, shape=shape, direction=direction, use=use)
308308
class(output) = 'magbin'
309309
return(output)
310310
}

R/magimage.R

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ magimage = function(x, y, z, zlim, xlim, ylim, col = grey((0:1e3)/1e3), add = FA
22
useRaster=TRUE, asp=1, magmap=TRUE, locut=0.4, hicut=0.995, flip=FALSE,
33
range=c(0,1), type = "quan", stretch="asinh", stretchscale='auto',
44
bad=NA, clip="", axes=TRUE, frame.plot=TRUE, sparse='auto', qdiff=FALSE,
5-
rem_med=FALSE, doplot=TRUE, ...){
5+
rem_med=FALSE, doplot=TRUE, interact=FALSE, ...){
66
if(is.list(x)){
77
if(!all(names(x) %in% c('x','y','z'))){
88
message('x is a list (and not just x/y/z components), perhaps you want to pass a subset of this to magimage?')
@@ -108,6 +108,23 @@ magimage = function(x, y, z, zlim, xlim, ylim, col = grey((0:1e3)/1e3), add = FA
108108
}
109109
}
110110

111+
if(interact){
112+
if(!requireNamespace("plotly", quietly = TRUE)){
113+
stop('The plotly package is needed for this function to work. Please install it from CRAN.', call. = FALSE)
114+
}
115+
116+
fig = plotly::plot_ly(x=x, y=y, z=z, type = "heatmap", colors = col, transpose=TRUE)
117+
118+
fig = plotly::layout(
119+
p = fig,
120+
xaxis = list(range = xlim, scaleanchor = "y"), # Set x-axis limits and anchor to y-axis
121+
yaxis = list(range = ylim) # Set y-axis limits
122+
)
123+
124+
print(fig)
125+
return(invisible(NULL))
126+
}
127+
111128
if(!doplot){
112129
return(invisible(list(x=x, y=y, z=z)))
113130
}

R/magimageRGB.R

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,26 @@ magimageRGB<-function(x, y, R, G, B, saturation=1, zlim, xlim, ylim, add = FALSE
8888
rm(Ba)
8989
}
9090

91-
# R=R-min(R)
92-
# R=R/max(R)
93-
# G=G-min(G)
94-
# G=G/max(G)
95-
# B=B-min(B)
96-
# B=B/max(B)
91+
z = matrix(1:length(R),dim(R)[1])
92+
col = rgb(R,G,B)
9793

98-
do.call('image',c(list(x=x, y=y, z=matrix(1:length(R),dim(R)[1]), zlim=zlim, xlim=xlim, ylim=ylim, col=rgb(R,G,B), add=add, useRaster=useRaster, axes=FALSE, asp=asp, xlab='', ylab='', main=''), dotsimage))
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+
110+
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))
99111
if(add==FALSE){
100112
if(axes){
101113
magaxis(...)

man/magimage.Rd

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ magimage(x, y, z, zlim, xlim, ylim, col = grey((0:1000)/1000), add = FALSE,
1313
useRaster = TRUE, asp = 1, magmap = TRUE, locut = 0.4, hicut = 0.995, flip = FALSE,
1414
range = c(0, 1), type = "quan", stretch = "asinh", stretchscale = 'auto', bad = NA,
1515
clip = "", axes = TRUE, frame.plot = TRUE, sparse = 'auto', qdiff = FALSE,
16-
rem_med = FALSE, doplot = TRUE, ...)
16+
rem_med = FALSE, doplot = TRUE, interact = FALSE, ...)
1717

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,
@@ -105,6 +105,9 @@ Logical; should the \code{median} of the \option{image} be subtracted or not? Th
105105
}
106106
\item{doplot}{
107107
Logical; if TRUE then gnerates the image. If FALSE then just return the output below (with z scaled as request).
108+
}
109+
\item{interact}{
110+
Logical; if TRUE then an interactive \code{plotly} viewer will be displayed. You will need the \code{plotly} package from CRAN for this to work.
108111
}
109112
\item{\dots}{
110113
Arguments to be parsed to \code{image} and \code{magaxis} as relevant (this is checked for internally by argument name). See \code{\link{image}} and \code{\link{magaxis}} for details.

0 commit comments

Comments
 (0)