Skip to content

Commit

Permalink
Allow ggneuron to work with 3D points
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderbates committed Jul 13, 2024
1 parent 61ed59c commit b25e034
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 0 deletions.
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ S3method(banc_decapitate,mesh3d)
S3method(banc_decapitate,neuron)
S3method(banc_decapitate,neuronlist)
S3method(geom_neuron,"NULL")
S3method(geom_neuron,data.frame)
S3method(geom_neuron,hxsurf)
S3method(geom_neuron,list)
S3method(geom_neuron,matrix)
S3method(geom_neuron,mesh3d)
S3method(geom_neuron,neuron)
S3method(geom_neuron,neuronlist)
Expand Down
29 changes: 29 additions & 0 deletions R/ggplot2.R
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,35 @@ geom_neuron.list <- function(x = NULL, rotation_matrix = NULL, root = 3, low = "
}
}

#' @rdname geom_neuron
#' @method geom_neuron matrix
#' @export
geom_neuron.matrix <- function(x = NULL, rotation_matrix = NULL, root = 3, low = "navy", high = "turquoise",
stat = "identity", position = "identity", na.rm = FALSE, show.legend = NA,
inherit.aes = FALSE, ...) {
x<- as.data.frame(nat::xyzmatrix(x))
list(
ggplot2::geom_point(data = x, mapping = ggplot2::aes(x = .data$X, y = .data$Y, color = .data$Z),
size = root, ...),
ggplot2::scale_color_gradient(low = low, high = high),
ggnewscale::new_scale_colour()
)
}

#' @rdname geom_neuron
#' @method geom_neuron data.frame
#' @export
geom_neuron.data.frame <- function(x = NULL, rotation_matrix = NULL, root = 3, low = "navy", high = "turquoise",
stat = "identity", position = "identity", na.rm = FALSE, show.legend = NA,
inherit.aes = FALSE, ...) {
geom_neuron.matrix(x, rotation_matrix = rotation_matrix, root = root,
low = low, high = high,
stat = stat, position = position,
na.rm = FALSE, show.legend = NA,
inherit.aes = FALSE,
...)
}

#' Create a ggplot2 Visualisation of Neuron Objects
#'
#' @description
Expand Down
15 changes: 15 additions & 0 deletions R/xform.R
Original file line number Diff line number Diff line change
Expand Up @@ -547,3 +547,18 @@ banc_mirror <- function(x,
return(x)

}

# hidden, for now
banc_lr_position <- function (x, units = c("nm", "um", "raw"), group = FALSE, ...) {
xyz = xyzmatrix(x)
xyzt = banc_mirror(xyz, units = units, ...)
lrdiff = xyzt[, 1] - xyz[, 1]
if (group) {
if (!is.neuronlist(x))
stop("I only know how to group results for neuronlists")
df = data.frame(lrdiff = lrdiff, id = rep(names(x), nvertices(x)))
dff = summarise(group_by(df, .data$id), lrdiff = mean(lrdiff))
lrdiff = dff$lrdiff[match(names(x), dff$id)]
}
lrdiff
}
1 change: 1 addition & 0 deletions man/bancr-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 45 additions & 0 deletions man/geom_neuron.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b25e034

Please sign in to comment.