Skip to content

Commit

Permalink
Merge branch 'main' of github.com:flyconnectome/bancr
Browse files Browse the repository at this point in the history
  • Loading branch information
jefferis committed Jul 16, 2024
2 parents f336b46 + 6385f82 commit 0f1eb69
Show file tree
Hide file tree
Showing 4 changed files with 108 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
45 changes: 45 additions & 0 deletions R/ggplot2.R
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,51 @@ geom_neuron.NULL <- function(x = NULL, rotation_matrix = NULL, root = 3, low = "
)
}

#' @rdname geom_neuron
#' @method geom_neuron list
#' @export
geom_neuron.list <- 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, ...) {

if(length(x)){
geom_neuron.neuronlist(x=x, rotation_matrix=rotation_matrix, low=low, high=high,
stat=stat, position=position, na.rm=na.rm, show.legend=show.legend, inherit.aes=inherit.aes,
...)
}else{
geom_neuron.NULL(x = x, ...)
}
}

#' @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
}
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 0f1eb69

Please sign in to comment.