Skip to content

Commit

Permalink
Merge pull request #27 from amcdavid/main
Browse files Browse the repository at this point in the history
Move some plot-"enhancing" packages to Suggests
  • Loading branch information
ilyakorsunsky authored Aug 11, 2022
2 parents 0e93b27 + 0b428bc commit d9d50dc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Imports:
tidyr,
rlang,
RColorBrewer,
RANN
RANN
VignetteBuilder: knitr
Depends:
R (>= 2.10)
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import(RANN)
import(RColorBrewer)
import(data.table)
import(ggplot2)
import(ggrepel)
import(irlba)
import(stats)
import(tibble)
Expand Down
21 changes: 14 additions & 7 deletions R/plotReference.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
#' @param show.labels Show cell type labels
#' @param show.centroids Plot soft cluster centroid locations
#' @import ggplot2
#' @import ggrastr
#' @import RColorBrewer
#' @import ggrepel
#' @import uwot
#' @return A ggplot object.
#' @export
Expand Down Expand Up @@ -44,9 +42,14 @@ plotReference = function(reference, # Symphony reference object
contour_var = "ndensity", bins = bins, h = bandwidth)
if (!is.null(celltype.colors)) { p = p + scale_fill_manual(values = celltype.colors) +
labs(fill = color.by)}
} else {
} else {
if(requireNamespace('ggrastr')){
# Plot as individual points
p = p + geom_point_rast(aes(col = get(color.by)), size = 0.3, stroke = 0.2, shape = 16)
p = p + ggrastr::geom_point_rast(aes(col = get(color.by)), size = 0.3, stroke = 0.2, shape = 16)
} else{
message('Install ggrastr to plot cell as raster. Useful if there are many cells.')
p = p + geom_point(aes(col = get(color.by)), size = 0.3, stroke = 0.2, shape = 16)
}
if (!is.null(celltype.colors)) { p = p + scale_color_manual(values = celltype.colors) + labs(color = color.by)}
}

Expand Down Expand Up @@ -74,9 +77,13 @@ plotReference = function(reference, # Symphony reference object
dplyr::group_by_at(color.by) %>% #group_by_at takes variable column name
dplyr::select(UMAP1, UMAP2) %>%
dplyr::summarize_all(median)

p = p + ggrepel::geom_text_repel(data = labels.cent, aes(x= UMAP1, y = UMAP2, label = get(color.by)),
segment.alpha = 0.5, segment.size = 0.2, box.padding = 0.01, color = 'black')
if(requireNamespace('ggrepel')){
p = p + geom_text_repel(data = labels.cent, aes(x= UMAP1, y = UMAP2, label = get(color.by)),
segment.alpha = 0.5, segment.size = 0.2, box.padding = 0.01, color = 'black')
} else{
message('Install ggrepel to layout labels nicely.')
p = p + ggplot2::geom_text(data = labels.cent, aes(x= UMAP1, y = UMAP2, label = get(color.by)), color = 'black')
}
}

if (!show.legend) {
Expand Down

0 comments on commit d9d50dc

Please sign in to comment.