From 3a3c409ca0a6d261c275e7b49b0ff3cc82786767 Mon Sep 17 00:00:00 2001 From: jiajic <72078254+jiajic@users.noreply.github.com> Date: Thu, 25 Jan 2024 22:31:04 -0500 Subject: [PATCH 1/2] fix: rework image plotting version bump --- DESCRIPTION | 4 +- NEWS.md | 6 +- R/generics.R | 4 + R/gg_annotation_raster.R | 113 +++ R/gg_info_layers.R | 146 +--- R/vis_spatial.R | 1412 ++++++++++++++++++----------------- man/gg_annotation_raster.Rd | 27 + 7 files changed, 869 insertions(+), 843 deletions(-) create mode 100644 R/generics.R create mode 100644 R/gg_annotation_raster.R create mode 100644 man/gg_annotation_raster.Rd diff --git a/DESCRIPTION b/DESCRIPTION index 8a19dc3..0293af8 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: GiottoVisuals Title: Visuals for the Giotto spatial biology analysis ecosystem -Version: 0.1.3 +Version: 0.1.4 Authors@R: c( person("Ruben", "Dries", email = "rubendries@gmail.com", role = c("aut", "cre")), @@ -82,6 +82,8 @@ Collate: 'colorRamp2.R' 'color_palettes.R' 'dd.R' + 'generics.R' + 'gg_annotation_raster.R' 'gg_info_layers.R' 'globals.R' 'gstop.R' diff --git a/NEWS.md b/NEWS.md index 2f0ea9c..bee41cd 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,7 +1,11 @@ -# GiottoVisuals 0.1.3 (2024/01/25) +# GiottoVisuals 0.1.4 (2024/01/25) ## bug fixes - fix plotting color gradient when using param `point_shape = "no_border"` +- fix image NA value [#865](https://github.com/drieslab/Giotto/issues/865) by rbutleriii + +## new +- `gg_annotation_raster()` internal generic for adding a `giottoImage`, `giottoLargeImage`, or `list` thereof to a `ggplot` object # GiottoVisuals 0.1.2 (2023/01/12) diff --git a/R/generics.R b/R/generics.R new file mode 100644 index 0000000..b584a77 --- /dev/null +++ b/R/generics.R @@ -0,0 +1,4 @@ + +# internals +setOldClass("gg") +setGeneric("gg_annotation_raster", function(ggobj, gimage, ...) standardGeneric("gg_annotation_raster")) diff --git a/R/gg_annotation_raster.R b/R/gg_annotation_raster.R new file mode 100644 index 0000000..ad37514 --- /dev/null +++ b/R/gg_annotation_raster.R @@ -0,0 +1,113 @@ + +#' @name gg_annotation_raster +#' @keywords internal +#' @title Append image to ggplot as annotation_raster +#' @param ggobj ggplot2 gg object +#' @param gimage `giottoLargeImage`, `giottoImage` or `list` thereof +#' @return `gg` object with images to plot appended as annotation rasters +NULL + +#' @rdname gg_annotation_raster +setMethod( + "gg_annotation_raster", + signature(ggobj = "gg", gimage = "list"), + function(ggobj, gimage, ...) + { + for(i in seq_along(gimage)) { + ggobj <- gg_annotation_raster(ggobj, gimage[[i]], ...) + } + return(ggobj) + } +) + +#' @rdname gg_annotation_raster +setMethod( + "gg_annotation_raster", + signature(ggobj = "gg", gimage = "giottoImage"), + function(ggobj, gimage, ...) + { + # extract min and max from object + my_xmax = gimage@minmax[1] + my_xmin = gimage@minmax[2] + my_ymax = gimage@minmax[3] + my_ymin = gimage@minmax[4] + + # convert giotto image object into array + img_array = as.numeric(gimage@mg_object[[1]]) + + # extract adjustments from object + xmax_b = gimage@boundaries[1] + xmin_b = gimage@boundaries[2] + ymax_b = gimage@boundaries[3] + ymin_b = gimage@boundaries[4] + + # append to ggobj + ggobj <- ggobj + annotation_raster( + img_array, + xmin = my_xmin-xmin_b, xmax = my_xmax+xmax_b, + ymin = my_ymin-ymin_b, ymax = my_ymax+ymax_b + ) + + # TODO geom_raster to accommodate single-channel + return(ggobj) + } +) + +#' @rdname gg_annotation_raster +setMethod( + "gg_annotation_raster", + signature(ggobj = "gg", gimage = "giottoLargeImage"), + function(ggobj, gimage, ...) + { + # get plotting minmax + extent = terra::ext(gimage@raster_object)[1:4] + xmin = extent[['xmin']] + xmax = extent[['xmax']] + ymin = extent[['ymin']] + ymax = extent[['ymax']] + + # convert raster object into array with 3 channels + img_array = terra::as.array(gimage@raster_object) + + # TODO: check if required, fixes NaN values + # replacing NA's by zero or another value directly in raster object? + # raster[is.na(raster[])] <- 0 + if (is.nan(max(img_array[,,1]))) { + img_array[,,1][is.nan(img_array[,,1])] = max(img_array[,,1], na.rm = TRUE) + } + + if(dim(img_array)[3] > 1) { + if(is.nan(max(img_array[,,2]))) { + img_array[,,2][is.nan(img_array[,,2])] = max(img_array[,,2], na.rm = TRUE) + } + } + + if(dim(img_array)[3] > 2) { + if(is.nan(max(img_array[,,3]))) { + img_array[,,3][is.nan(img_array[,,3])] = max(img_array[,,3], na.rm = TRUE) + } + } + + img_array = img_array/max(img_array, na.rm = TRUE) + if(dim(img_array)[3] == 1) { + img_array_RGB = array(NA, dim = c(dim(img_array)[1:2],3)) + img_array_RGB[,,1:3] = img_array + } else { + img_array_RGB = img_array + } + + # handle NA values + img_array_RGB[is.na(img_array_RGB)] <- 0 + + # append to ggobj + ggobj <- ggobj + annotation_raster( + img_array_RGB, + xmin = xmin, xmax = xmax, + ymin = ymin, ymax = ymax + ) + + # TODO geom_raster to accommodate single-channel + return(ggobj) + } +) + diff --git a/R/gg_info_layers.R b/R/gg_info_layers.R index 0d48bac..efd2609 100644 --- a/R/gg_info_layers.R +++ b/R/gg_info_layers.R @@ -1350,151 +1350,9 @@ plot_spat_image_layer_ggplot = function(gg_obj, # Assign region to plot gg_obj = gg_obj + geom_blank(data = spat_ext, aes_string(sdimx, sdimy)) - if((inherits(gimage, 'list') | is.vector(gimage)) & length(gimage) > 1) { - - for(i in 1:length(gimage)) { - - if(inherits(gimage[[i]], 'giottoImage')) { - # extract min and max from object - my_xmax = gimage[[i]]@minmax[1] - my_xmin = gimage[[i]]@minmax[2] - my_ymax = gimage[[i]]@minmax[3] - my_ymin = gimage[[i]]@minmax[4] - - # convert giotto image object into array - img_array = as.numeric(gimage[[i]]@mg_object[[1]]) - - # extract adjustments from object - xmax_b = gimage[[i]]@boundaries[1] - xmin_b = gimage[[i]]@boundaries[2] - ymax_b = gimage[[i]]@boundaries[3] - ymin_b = gimage[[i]]@boundaries[4] - - gg_obj = gg_obj + annotation_raster(img_array, - xmin = my_xmin-xmin_b, xmax = my_xmax+xmax_b, - ymin = my_ymin-ymin_b, ymax = my_ymax+ymax_b) - - # TODO geom_raster to accommodate single-channel - - } else if(inherits(gimage[[i]], 'giottoLargeImage')) { - # get plotting minmax - extent = terra::ext(gimage[[i]]@raster_object)[1:4] - xmin = extent[['xmin']] - xmax = extent[['xmax']] - ymin = extent[['ymin']] - ymax = extent[['ymax']] - - # convert raster object into array with 3 channels - img_array = terra::as.array(gimage[[i]]@raster_object) - - # TODO: check if required, fixes NaN values - # replacing NA's by zero or another value directly in raster object? - # raster[is.na(raster[])] <- 0 - if(is.nan(max(img_array[,,1]))) { - img_array[,,1][is.nan(img_array[,,1])] = max(img_array[,,1], na.rm = T) - } - - if(dim(img_array)[3] > 1) { - if(is.nan(max(img_array[,,2]))) { - img_array[,,2][is.nan(img_array[,,2])] = max(img_array[,,2], na.rm = T) - } - } - - if(dim(img_array)[3] > 2) { - if(is.nan(max(img_array[,,3]))) { - img_array[,,3][is.nan(img_array[,,3])] = max(img_array[,,3], na.rm = T) - } - } - - - + # Assign image(s) to plot + gg_obj <- gg_annotation_raster(ggobj = gg_obj, gimage = gimage) - img_array = img_array/max(img_array, na.rm = TRUE) - if(dim(img_array)[3] == 1) { - img_array_RGB = array(NA, dim = c(dim(img_array)[1:2],3)) - img_array_RGB[,,1:3] = img_array - img_array_RGB[is.na(img_array_RGB)] = 0 - } else { - img_array_RGB = img_array - } - - gg_obj = gg_obj + annotation_raster(img_array_RGB, - xmin = xmin, xmax = xmax, - ymin = ymin, ymax = ymax) - - # TODO geom_raster to accommodate single-channel - } - - } - - } else { - - if(methods::is(gimage, 'giottoImage')) { - # extract min and max from object - my_xmax = gimage@minmax[1] - my_xmin = gimage@minmax[2] - my_ymax = gimage@minmax[3] - my_ymin = gimage@minmax[4] - - # convert giotto image object into array - img_array = as.numeric(gimage@mg_object[[1]]) - - # extract adjustments from object - xmax_b = gimage@boundaries[1] - xmin_b = gimage@boundaries[2] - ymax_b = gimage@boundaries[3] - ymin_b = gimage@boundaries[4] - - gg_obj = gg_obj + annotation_raster(img_array, - xmin = my_xmin-xmin_b, xmax = my_xmax+xmax_b, - ymin = my_ymin-ymin_b, ymax = my_ymax+ymax_b) - - } else if(methods::is(gimage, 'giottoLargeImage')) { - # get plotting minmax - extent = terra::ext(gimage@raster_object)[1:4] - xmin = extent[['xmin']] - xmax = extent[['xmax']] - ymin = extent[['ymin']] - ymax = extent[['ymax']] - - # convert raster object into array with 3 channels - img_array = terra::as.array(gimage@raster_object) - - # TODO: check if required, fixes NaN values - # replacing NA's by zero or another value directy in raster object? - # raster[is.na(raster[])] <- 0 - if(is.nan(max(img_array[,,1]))) { - img_array[,,1][is.nan(img_array[,,1])] = max(img_array[,,1], na.rm = T) - } - - if(dim(img_array)[3] > 1) { - if(is.nan(max(img_array[,,2]))) { - img_array[,,2][is.nan(img_array[,,2])] = max(img_array[,,2], na.rm = T) - } - } - - if(dim(img_array)[3] > 2) { - if(is.nan(max(img_array[,,3]))) { - img_array[,,3][is.nan(img_array[,,3])] = max(img_array[,,3], na.rm = T) - } - } - - img_array = img_array/max(img_array, na.rm = TRUE) - if(dim(img_array)[3] == 1) { - img_array_RGB = array(NA, dim = c(dim(img_array)[1:2],3)) - img_array_RGB[,,1:3] = img_array - img_array_RGB[is.na(img_array_RGB)] = 0 - } else { - img_array_RGB = img_array - } - - gg_obj <- gg_obj + - annotation_raster(img_array_RGB, - xmin = xmin, xmax = xmax, - ymin = ymin, ymax = ymax) - } - - } if(!is.null(spatlocs)) { gg_obj <- gg_obj + diff --git a/R/vis_spatial.R b/R/vis_spatial.R index a504ee1..d1afd83 100644 --- a/R/vis_spatial.R +++ b/R/vis_spatial.R @@ -45,66 +45,68 @@ #' @details Description of parameters. #' @keywords internal #' @seealso \code{\link{spatPlot3D}} -.spatPlot2D_single = function(gobject, - feat_type = NULL, - spat_unit = NULL, - show_image = F, - gimage = NULL, - image_name = NULL, - largeImage_name = NULL, - spat_loc_name = NULL, - sdimx = 'sdimx', - sdimy = 'sdimy', - spat_enr_names = NULL, - cell_color = NULL, - color_as_factor = T, - cell_color_code = NULL, - cell_color_gradient = NULL, - gradient_midpoint = NULL, - gradient_style = 'divergent', - gradient_limits = NULL, - select_cell_groups = NULL, - select_cells = NULL, - point_shape = c('border', 'no_border', 'voronoi'), - point_size = 3, - point_alpha = 1, - point_border_col = 'black', - point_border_stroke = 0.1, - show_cluster_center = F, - show_center_label = F, - center_point_size = 4, - center_point_border_col = 'black', - center_point_border_stroke = 0.1, - label_size = 4, - label_fontface = 'bold', - show_network = F, - spatial_network_name = 'Delaunay_network', - network_color = NULL, - network_alpha = 1, - show_grid = F, - spatial_grid_name = 'spatial_grid', - grid_color = NULL, - show_other_cells = T, - other_cell_color = 'lightgrey', - other_point_size = 1, - other_cells_alpha = 0.1, - coord_fix_ratio = 1, - title = NULL, - show_legend = T, - legend_text = 8, - legend_symbol_size = 1, - background_color = 'white', - vor_border_color = 'white', - vor_max_radius = 200, - vor_alpha = 1, - axis_text = 8, - axis_title = 8, - show_plot = NA, - return_plot = NA, - save_plot = NA, - verbose = FALSE, - save_param = list(), - default_save_name = 'spatPlot2D_single') { +.spatPlot2D_single = function( + gobject, + feat_type = NULL, + spat_unit = NULL, + show_image = F, + gimage = NULL, + image_name = NULL, + largeImage_name = NULL, + spat_loc_name = NULL, + sdimx = 'sdimx', + sdimy = 'sdimy', + spat_enr_names = NULL, + cell_color = NULL, + color_as_factor = T, + cell_color_code = NULL, + cell_color_gradient = NULL, + gradient_midpoint = NULL, + gradient_style = 'divergent', + gradient_limits = NULL, + select_cell_groups = NULL, + select_cells = NULL, + point_shape = c('border', 'no_border', 'voronoi'), + point_size = 3, + point_alpha = 1, + point_border_col = 'black', + point_border_stroke = 0.1, + show_cluster_center = F, + show_center_label = F, + center_point_size = 4, + center_point_border_col = 'black', + center_point_border_stroke = 0.1, + label_size = 4, + label_fontface = 'bold', + show_network = F, + spatial_network_name = 'Delaunay_network', + network_color = NULL, + network_alpha = 1, + show_grid = F, + spatial_grid_name = 'spatial_grid', + grid_color = NULL, + show_other_cells = T, + other_cell_color = 'lightgrey', + other_point_size = 1, + other_cells_alpha = 0.1, + coord_fix_ratio = 1, + title = NULL, + show_legend = T, + legend_text = 8, + legend_symbol_size = 1, + background_color = 'white', + vor_border_color = 'white', + vor_max_radius = 200, + vor_alpha = 1, + axis_text = 8, + axis_title = 8, + show_plot = NA, + return_plot = NA, + save_plot = NA, + verbose = FALSE, + save_param = list(), + default_save_name = 'spatPlot2D_single' +) { assert_giotto(gobject) @@ -291,14 +293,16 @@ ## plot image ## if(show_image == TRUE & !is.null(gimage)) { - pl = plot_spat_image_layer_ggplot(gg_obj = pl, - gobject = gobject, - feat_type = feat_type, - spat_unit = spat_unit, - spat_loc_name = spat_loc_name, - gimage = gimage, - sdimx = sdimx, - sdimy = sdimy) + pl = plot_spat_image_layer_ggplot( + gg_obj = pl, + gobject = gobject, + feat_type = feat_type, + spat_unit = spat_unit, + spat_loc_name = spat_loc_name, + gimage = gimage, + sdimx = sdimx, + sdimy = sdimy + ) } ## plot spatial network @@ -324,96 +328,102 @@ ## plot point layer if(point_shape == 'border') { - pl = plot_spat_point_layer_ggplot(ggobject = pl, - instrs = instructions(gobject), - sdimx = sdimx, - sdimy = sdimy, - cell_locations_metadata_selected = cell_locations_metadata_selected, - cell_locations_metadata_other = cell_locations_metadata_other, - cell_color = cell_color, - color_as_factor = color_as_factor, - cell_color_code = cell_color_code, - cell_color_gradient = cell_color_gradient, - gradient_midpoint = gradient_midpoint, - gradient_style = gradient_style, - gradient_limits = gradient_limits, - select_cell_groups = select_cell_groups, - select_cells = select_cells, - point_size = point_size, - point_alpha = point_alpha, - point_border_stroke = point_border_stroke, - point_border_col = point_border_col, - show_cluster_center = show_cluster_center, - show_center_label = show_center_label, - center_point_size = center_point_size, - center_point_border_col = center_point_border_col, - center_point_border_stroke = center_point_border_stroke, - label_size = label_size, - label_fontface = label_fontface, - show_other_cells = show_other_cells, - other_cell_color = other_cell_color, - other_point_size = other_point_size, - show_legend = show_legend) + pl = plot_spat_point_layer_ggplot( + ggobject = pl, + instrs = instructions(gobject), + sdimx = sdimx, + sdimy = sdimy, + cell_locations_metadata_selected = cell_locations_metadata_selected, + cell_locations_metadata_other = cell_locations_metadata_other, + cell_color = cell_color, + color_as_factor = color_as_factor, + cell_color_code = cell_color_code, + cell_color_gradient = cell_color_gradient, + gradient_midpoint = gradient_midpoint, + gradient_style = gradient_style, + gradient_limits = gradient_limits, + select_cell_groups = select_cell_groups, + select_cells = select_cells, + point_size = point_size, + point_alpha = point_alpha, + point_border_stroke = point_border_stroke, + point_border_col = point_border_col, + show_cluster_center = show_cluster_center, + show_center_label = show_center_label, + center_point_size = center_point_size, + center_point_border_col = center_point_border_col, + center_point_border_stroke = center_point_border_stroke, + label_size = label_size, + label_fontface = label_fontface, + show_other_cells = show_other_cells, + other_cell_color = other_cell_color, + other_point_size = other_point_size, + show_legend = show_legend + ) } else if(point_shape == 'no_border') { - pl = plot_spat_point_layer_ggplot_noFILL(ggobject = pl, - instrs = instructions(gobject), - sdimx = sdimx, - sdimy = sdimy, - cell_locations_metadata_selected = cell_locations_metadata_selected, - cell_locations_metadata_other = cell_locations_metadata_other, - cell_color = cell_color, - color_as_factor = color_as_factor, - cell_color_code = cell_color_code, - cell_color_gradient = cell_color_gradient, - gradient_midpoint = gradient_midpoint, - gradient_style = gradient_style, - gradient_limits = gradient_limits, - select_cell_groups = select_cell_groups, - select_cells = select_cells, - point_size = point_size, - point_alpha = point_alpha, - show_cluster_center = show_cluster_center, - show_center_label = show_center_label, - center_point_size = center_point_size, - label_size = label_size, - label_fontface = label_fontface, - show_other_cells = show_other_cells, - other_cell_color = other_cell_color, - other_point_size = other_point_size, - show_legend = show_legend) + pl = plot_spat_point_layer_ggplot_noFILL( + ggobject = pl, + instrs = instructions(gobject), + sdimx = sdimx, + sdimy = sdimy, + cell_locations_metadata_selected = cell_locations_metadata_selected, + cell_locations_metadata_other = cell_locations_metadata_other, + cell_color = cell_color, + color_as_factor = color_as_factor, + cell_color_code = cell_color_code, + cell_color_gradient = cell_color_gradient, + gradient_midpoint = gradient_midpoint, + gradient_style = gradient_style, + gradient_limits = gradient_limits, + select_cell_groups = select_cell_groups, + select_cells = select_cells, + point_size = point_size, + point_alpha = point_alpha, + show_cluster_center = show_cluster_center, + show_center_label = show_center_label, + center_point_size = center_point_size, + label_size = label_size, + label_fontface = label_fontface, + show_other_cells = show_other_cells, + other_cell_color = other_cell_color, + other_point_size = other_point_size, + show_legend = show_legend + ) } else if(point_shape == 'voronoi') { - pl = plot_spat_voronoi_layer_ggplot(ggobject = pl, - instrs = instructions(gobject), - sdimx = sdimx, - sdimy = sdimy, - cell_locations_metadata_selected = cell_locations_metadata_selected, - cell_locations_metadata_other = cell_locations_metadata_other, - cell_color = cell_color, - color_as_factor = color_as_factor, - cell_color_code = cell_color_code, - cell_color_gradient = cell_color_gradient, - gradient_midpoint = gradient_midpoint, - gradient_style = gradient_style, - gradient_limits = gradient_limits, - select_cell_groups = select_cell_groups, - select_cells = select_cells, - point_size = point_size, - point_alpha = point_alpha, - show_cluster_center = show_cluster_center, - show_center_label = show_center_label, - center_point_size = center_point_size, - label_size = label_size, - label_fontface = label_fontface, - show_other_cells = show_other_cells, - other_cell_color = other_cell_color, - other_point_size = other_point_size, - background_color = background_color, - vor_border_color = vor_border_color, - vor_max_radius = vor_max_radius, - vor_alpha = vor_alpha, - show_legend = show_legend) + pl = plot_spat_voronoi_layer_ggplot( + ggobject = pl, + instrs = instructions(gobject), + sdimx = sdimx, + sdimy = sdimy, + cell_locations_metadata_selected = cell_locations_metadata_selected, + cell_locations_metadata_other = cell_locations_metadata_other, + cell_color = cell_color, + color_as_factor = color_as_factor, + cell_color_code = cell_color_code, + cell_color_gradient = cell_color_gradient, + gradient_midpoint = gradient_midpoint, + gradient_style = gradient_style, + gradient_limits = gradient_limits, + select_cell_groups = select_cell_groups, + select_cells = select_cells, + point_size = point_size, + point_alpha = point_alpha, + show_cluster_center = show_cluster_center, + show_center_label = show_center_label, + center_point_size = center_point_size, + label_size = label_size, + label_fontface = label_fontface, + show_other_cells = show_other_cells, + other_cell_color = other_cell_color, + other_point_size = other_point_size, + background_color = background_color, + vor_border_color = vor_border_color, + vor_max_radius = vor_max_radius, + vor_alpha = vor_alpha, + show_legend = show_legend + ) } @@ -515,136 +525,140 @@ #' @param vor_alpha transparency of voronoi 'cells' #' @details coord_fix_ratio: set to NULL to use default ggplot parameters #' @export -spatPlot2D = function(gobject, - spat_unit = NULL, - feat_type = NULL, - show_image = F, - gimage = NULL, - image_name = NULL, - largeImage_name = NULL, - group_by = NULL, - group_by_subset = NULL, - spat_loc_name = NULL, - sdimx = 'sdimx', - sdimy = 'sdimy', - spat_enr_names = NULL, - cell_color = NULL, - color_as_factor = T, - cell_color_code = NULL, - cell_color_gradient = NULL, - gradient_midpoint = NULL, - gradient_style = c('divergent', 'sequential'), - gradient_limits = NULL, - select_cell_groups = NULL, - select_cells = NULL, - point_shape = c('border', 'no_border', 'voronoi'), - point_size = 3, - point_alpha = 1, - point_border_col = 'black', - point_border_stroke = 0.1, - show_cluster_center = F, - show_center_label = F, - center_point_size = 4, - center_point_border_col = 'black', - center_point_border_stroke = 0.1, - label_size = 4, - label_fontface = 'bold', - show_network = F, - spatial_network_name = 'Delaunay_network', - network_color = NULL, - network_alpha = 1, - show_grid = F, - spatial_grid_name = 'spatial_grid', - grid_color = NULL, - show_other_cells = T, - other_cell_color = 'lightgrey', - other_point_size = 1, - other_cells_alpha = 0.1, - coord_fix_ratio = 1, - title = NULL, - show_legend = T, - legend_text = 10, - legend_symbol_size = 2, - background_color = 'white', - vor_border_color = 'white', - vor_max_radius = 200, - vor_alpha = 1, - axis_text = 8, - axis_title = 8, - cow_n_col = NULL, - cow_rel_h = 1, - cow_rel_w = 1, - cow_align = 'h', - show_plot = NA, - return_plot = NA, - save_plot = NA, - save_param = list(), - default_save_name = 'spatPlot2D') { +spatPlot2D = function( + gobject, + spat_unit = NULL, + feat_type = NULL, + show_image = F, + gimage = NULL, + image_name = NULL, + largeImage_name = NULL, + group_by = NULL, + group_by_subset = NULL, + spat_loc_name = NULL, + sdimx = 'sdimx', + sdimy = 'sdimy', + spat_enr_names = NULL, + cell_color = NULL, + color_as_factor = T, + cell_color_code = NULL, + cell_color_gradient = NULL, + gradient_midpoint = NULL, + gradient_style = c('divergent', 'sequential'), + gradient_limits = NULL, + select_cell_groups = NULL, + select_cells = NULL, + point_shape = c('border', 'no_border', 'voronoi'), + point_size = 3, + point_alpha = 1, + point_border_col = 'black', + point_border_stroke = 0.1, + show_cluster_center = F, + show_center_label = F, + center_point_size = 4, + center_point_border_col = 'black', + center_point_border_stroke = 0.1, + label_size = 4, + label_fontface = 'bold', + show_network = F, + spatial_network_name = 'Delaunay_network', + network_color = NULL, + network_alpha = 1, + show_grid = F, + spatial_grid_name = 'spatial_grid', + grid_color = NULL, + show_other_cells = T, + other_cell_color = 'lightgrey', + other_point_size = 1, + other_cells_alpha = 0.1, + coord_fix_ratio = 1, + title = NULL, + show_legend = T, + legend_text = 10, + legend_symbol_size = 2, + background_color = 'white', + vor_border_color = 'white', + vor_max_radius = 200, + vor_alpha = 1, + axis_text = 8, + axis_title = 8, + cow_n_col = NULL, + cow_rel_h = 1, + cow_rel_w = 1, + cow_align = 'h', + show_plot = NA, + return_plot = NA, + save_plot = NA, + save_param = list(), + default_save_name = 'spatPlot2D' +) { assert_giotto(gobject) ## check group_by if(is.null(group_by)) { - .spatPlot2D_single(gobject = gobject, - spat_unit = spat_unit, - feat_type = feat_type, - show_image = show_image, - gimage = gimage, - image_name = image_name, - largeImage_name = largeImage_name, - spat_loc_name = spat_loc_name, - sdimx = sdimx, - sdimy = sdimy, - spat_enr_names = spat_enr_names, - cell_color = cell_color, - color_as_factor = color_as_factor, - cell_color_code = cell_color_code, - cell_color_gradient = cell_color_gradient, - gradient_midpoint = gradient_midpoint, - gradient_style = gradient_style, - gradient_limits = gradient_limits, - select_cell_groups = select_cell_groups, - select_cells = select_cells, - point_shape = point_shape, - point_size = point_size, - point_alpha = point_alpha, - point_border_col = point_border_col, - point_border_stroke = point_border_stroke, - show_cluster_center = show_cluster_center, - show_center_label = show_center_label, - center_point_size = center_point_size, - center_point_border_col = center_point_border_col, - center_point_border_stroke = center_point_border_stroke, - label_size = label_size, - label_fontface = label_fontface, - show_network = show_network, - spatial_network_name = spatial_network_name, - network_color = network_color, - network_alpha = network_alpha, - show_grid = show_grid, - spatial_grid_name = spatial_grid_name, - grid_color = grid_color, - show_other_cells = show_other_cells, - other_cell_color = other_cell_color, - other_point_size = other_point_size, - other_cells_alpha = other_cells_alpha, - coord_fix_ratio = coord_fix_ratio, - show_legend = show_legend, - legend_text = legend_text, - legend_symbol_size = legend_symbol_size, - background_color = background_color, - vor_border_color = vor_border_color, - vor_max_radius = vor_max_radius, - vor_alpha = vor_alpha, - axis_text = axis_text, - axis_title = axis_title, - title = title, - show_plot = show_plot, - return_plot = return_plot, - save_plot = save_plot, - save_param = save_param, - default_save_name = default_save_name) + .spatPlot2D_single( + gobject = gobject, + spat_unit = spat_unit, + feat_type = feat_type, + show_image = show_image, + gimage = gimage, + image_name = image_name, + largeImage_name = largeImage_name, + spat_loc_name = spat_loc_name, + sdimx = sdimx, + sdimy = sdimy, + spat_enr_names = spat_enr_names, + cell_color = cell_color, + color_as_factor = color_as_factor, + cell_color_code = cell_color_code, + cell_color_gradient = cell_color_gradient, + gradient_midpoint = gradient_midpoint, + gradient_style = gradient_style, + gradient_limits = gradient_limits, + select_cell_groups = select_cell_groups, + select_cells = select_cells, + point_shape = point_shape, + point_size = point_size, + point_alpha = point_alpha, + point_border_col = point_border_col, + point_border_stroke = point_border_stroke, + show_cluster_center = show_cluster_center, + show_center_label = show_center_label, + center_point_size = center_point_size, + center_point_border_col = center_point_border_col, + center_point_border_stroke = center_point_border_stroke, + label_size = label_size, + label_fontface = label_fontface, + show_network = show_network, + spatial_network_name = spatial_network_name, + network_color = network_color, + network_alpha = network_alpha, + show_grid = show_grid, + spatial_grid_name = spatial_grid_name, + grid_color = grid_color, + show_other_cells = show_other_cells, + other_cell_color = other_cell_color, + other_point_size = other_point_size, + other_cells_alpha = other_cells_alpha, + coord_fix_ratio = coord_fix_ratio, + show_legend = show_legend, + legend_text = legend_text, + legend_symbol_size = legend_symbol_size, + background_color = background_color, + vor_border_color = vor_border_color, + vor_max_radius = vor_max_radius, + vor_alpha = vor_alpha, + axis_text = axis_text, + axis_title = axis_title, + title = title, + show_plot = show_plot, + return_plot = return_plot, + save_plot = save_plot, + save_param = save_param, + default_save_name = default_save_name + ) } else { @@ -724,64 +738,66 @@ spatPlot2D = function(gobject, spec_image_name = image_name } - pl = .spatPlot2D_single(gobject = temp_gobject, - spat_unit = spat_unit, - feat_type = feat_type, - show_image = show_image, - gimage = gimage, - image_name = spec_image_name, - spat_loc_name = spat_loc_name, - sdimx = sdimx, - sdimy = sdimy, - spat_enr_names = spat_enr_names, - cell_color = cell_color, - cell_color_code = cell_color_code, - color_as_factor = color_as_factor, - cell_color_gradient = cell_color_gradient, - gradient_midpoint = gradient_midpoint, - gradient_style = gradient_style, - gradient_limits = gradient_limits, - select_cell_groups = select_cell_groups, - select_cells = select_cells, - point_shape = point_shape, - point_size = point_size, - point_alpha = point_alpha, - point_border_col = point_border_col, - point_border_stroke = point_border_stroke, - show_cluster_center = show_cluster_center, - show_center_label = show_center_label, - center_point_size = center_point_size, - center_point_border_col = center_point_border_col, - center_point_border_stroke = center_point_border_stroke, - label_size = label_size, - label_fontface = label_fontface, - show_network = show_network, - spatial_network_name = spatial_network_name, - network_color = network_color, - network_alpha = network_alpha, - show_grid = show_grid, - spatial_grid_name = spatial_grid_name, - grid_color = grid_color, - show_other_cells = show_other_cells, - other_cell_color = other_cell_color, - other_point_size = other_point_size, - other_cells_alpha = other_cells_alpha, - coord_fix_ratio = coord_fix_ratio, - title = group, - show_legend = show_legend, - legend_text = legend_text, - legend_symbol_size = legend_symbol_size, - background_color = background_color, - vor_border_color = vor_border_color, - vor_max_radius = vor_max_radius, - vor_alpha = vor_alpha, - axis_text = axis_text, - axis_title = axis_title, - show_plot = FALSE, - return_plot = TRUE, - save_plot = FALSE, - save_param = list(), - default_save_name = 'spatPlot2D') + pl = .spatPlot2D_single( + gobject = temp_gobject, + spat_unit = spat_unit, + feat_type = feat_type, + show_image = show_image, + gimage = gimage, + image_name = spec_image_name, + spat_loc_name = spat_loc_name, + sdimx = sdimx, + sdimy = sdimy, + spat_enr_names = spat_enr_names, + cell_color = cell_color, + cell_color_code = cell_color_code, + color_as_factor = color_as_factor, + cell_color_gradient = cell_color_gradient, + gradient_midpoint = gradient_midpoint, + gradient_style = gradient_style, + gradient_limits = gradient_limits, + select_cell_groups = select_cell_groups, + select_cells = select_cells, + point_shape = point_shape, + point_size = point_size, + point_alpha = point_alpha, + point_border_col = point_border_col, + point_border_stroke = point_border_stroke, + show_cluster_center = show_cluster_center, + show_center_label = show_center_label, + center_point_size = center_point_size, + center_point_border_col = center_point_border_col, + center_point_border_stroke = center_point_border_stroke, + label_size = label_size, + label_fontface = label_fontface, + show_network = show_network, + spatial_network_name = spatial_network_name, + network_color = network_color, + network_alpha = network_alpha, + show_grid = show_grid, + spatial_grid_name = spatial_grid_name, + grid_color = grid_color, + show_other_cells = show_other_cells, + other_cell_color = other_cell_color, + other_point_size = other_point_size, + other_cells_alpha = other_cells_alpha, + coord_fix_ratio = coord_fix_ratio, + title = group, + show_legend = show_legend, + legend_text = legend_text, + legend_symbol_size = legend_symbol_size, + background_color = background_color, + vor_border_color = vor_border_color, + vor_max_radius = vor_max_radius, + vor_alpha = vor_alpha, + axis_text = axis_text, + axis_title = axis_title, + show_plot = FALSE, + return_plot = TRUE, + save_plot = FALSE, + save_param = list(), + default_save_name = 'spatPlot2D' + ) savelist[[group_id]] <- pl @@ -789,12 +805,14 @@ spatPlot2D = function(gobject, } # combine plots with cowplot - combo_plot <- cowplot::plot_grid(plotlist = savelist, - ncol = set_default_cow_n_col(cow_n_col = cow_n_col, - nr_plots = length(savelist)), - rel_heights = cow_rel_h, - rel_widths = cow_rel_w, - align = cow_align) + combo_plot <- cowplot::plot_grid( + plotlist = savelist, + ncol = set_default_cow_n_col(cow_n_col = cow_n_col, + nr_plots = length(savelist)), + rel_heights = cow_rel_h, + rel_widths = cow_rel_w, + align = cow_align + ) ## print plot @@ -1063,53 +1081,53 @@ spatDeconvPlot = function(gobject, #' @noRd #' @keywords internal .dimPlot2D_single <- function(gobject, - spat_unit = NULL, - feat_type = NULL, - dim_reduction_to_use = 'umap', - dim_reduction_name = NULL, - dim1_to_use = 1, - dim2_to_use = 2, - spat_enr_names = NULL, - show_NN_network = F, - nn_network_to_use = 'sNN', - network_name = 'sNN.pca', - cell_color = NULL, - color_as_factor = T, - cell_color_code = NULL, - cell_color_gradient = NULL, - gradient_midpoint = NULL, - gradient_style = c('divergent', 'sequential'), - gradient_limits = NULL, - select_cell_groups = NULL, - select_cells = NULL, - show_other_cells = T, - other_cell_color = 'lightgrey', - other_point_size = 0.5, - show_cluster_center = F, - show_center_label = T, - center_point_size = 4, - center_point_border_col = 'black', - center_point_border_stroke = 0.1, - label_size = 4, - label_fontface = 'bold', - edge_alpha = NULL, - point_shape = c('border', 'no_border'), - point_size = 1, - point_alpha = 1, - point_border_col = 'black', - point_border_stroke = 0.1, - title = NULL, - show_legend = T, - legend_text = 8, - legend_symbol_size = 1, - background_color = 'white', - axis_text = 8, - axis_title = 8, - show_plot = NA, - return_plot = NA, - save_plot = NA, - save_param = list(), - default_save_name = 'dimPlot2D_single' + spat_unit = NULL, + feat_type = NULL, + dim_reduction_to_use = 'umap', + dim_reduction_name = NULL, + dim1_to_use = 1, + dim2_to_use = 2, + spat_enr_names = NULL, + show_NN_network = F, + nn_network_to_use = 'sNN', + network_name = 'sNN.pca', + cell_color = NULL, + color_as_factor = T, + cell_color_code = NULL, + cell_color_gradient = NULL, + gradient_midpoint = NULL, + gradient_style = c('divergent', 'sequential'), + gradient_limits = NULL, + select_cell_groups = NULL, + select_cells = NULL, + show_other_cells = T, + other_cell_color = 'lightgrey', + other_point_size = 0.5, + show_cluster_center = F, + show_center_label = T, + center_point_size = 4, + center_point_border_col = 'black', + center_point_border_stroke = 0.1, + label_size = 4, + label_fontface = 'bold', + edge_alpha = NULL, + point_shape = c('border', 'no_border'), + point_size = 1, + point_alpha = 1, + point_border_col = 'black', + point_border_stroke = 0.1, + title = NULL, + show_legend = T, + legend_text = 8, + legend_symbol_size = 1, + background_color = 'white', + axis_text = 8, + axis_title = 8, + show_plot = NA, + return_plot = NA, + save_plot = NA, + save_param = list(), + default_save_name = 'dimPlot2D_single' ){ assert_giotto(gobject) @@ -1475,53 +1493,53 @@ dimPlot2D = function(gobject, if(is.null(group_by)) { .dimPlot2D_single(gobject = gobject, - spat_unit = spat_unit, - feat_type = feat_type, - dim_reduction_to_use = dim_reduction_to_use, - dim_reduction_name = dim_reduction_name, - dim1_to_use = dim1_to_use, - dim2_to_use = dim2_to_use, - spat_enr_names = spat_enr_names, - show_NN_network = show_NN_network, - nn_network_to_use = nn_network_to_use, - network_name = network_name, - cell_color = cell_color, - color_as_factor = color_as_factor, - cell_color_code = cell_color_code, - cell_color_gradient = cell_color_gradient, - gradient_midpoint = gradient_midpoint, - gradient_style = gradient_style, - gradient_limits = gradient_limits, - select_cell_groups = select_cell_groups, - select_cells = select_cells, - show_other_cells = show_other_cells, - other_cell_color = other_cell_color, - other_point_size = other_point_size, - show_cluster_center = show_cluster_center, - show_center_label = show_center_label, - center_point_size = center_point_size, - center_point_border_col = center_point_border_col, - center_point_border_stroke = center_point_border_stroke, - label_size = label_size, - label_fontface = label_fontface, - edge_alpha = edge_alpha, - point_shape = point_shape, - point_size = point_size, - point_alpha = point_alpha, - point_border_col = point_border_col, - point_border_stroke = point_border_stroke, - title = title, - show_legend = show_legend, - legend_text = legend_text, - legend_symbol_size = legend_symbol_size, - background_color = background_color, - axis_text = axis_text, - axis_title = axis_title, - show_plot = show_plot, - return_plot = return_plot, - save_plot = save_plot, - save_param = save_param, - default_save_name = default_save_name) + spat_unit = spat_unit, + feat_type = feat_type, + dim_reduction_to_use = dim_reduction_to_use, + dim_reduction_name = dim_reduction_name, + dim1_to_use = dim1_to_use, + dim2_to_use = dim2_to_use, + spat_enr_names = spat_enr_names, + show_NN_network = show_NN_network, + nn_network_to_use = nn_network_to_use, + network_name = network_name, + cell_color = cell_color, + color_as_factor = color_as_factor, + cell_color_code = cell_color_code, + cell_color_gradient = cell_color_gradient, + gradient_midpoint = gradient_midpoint, + gradient_style = gradient_style, + gradient_limits = gradient_limits, + select_cell_groups = select_cell_groups, + select_cells = select_cells, + show_other_cells = show_other_cells, + other_cell_color = other_cell_color, + other_point_size = other_point_size, + show_cluster_center = show_cluster_center, + show_center_label = show_center_label, + center_point_size = center_point_size, + center_point_border_col = center_point_border_col, + center_point_border_stroke = center_point_border_stroke, + label_size = label_size, + label_fontface = label_fontface, + edge_alpha = edge_alpha, + point_shape = point_shape, + point_size = point_size, + point_alpha = point_alpha, + point_border_col = point_border_col, + point_border_stroke = point_border_stroke, + title = title, + show_legend = show_legend, + legend_text = legend_text, + legend_symbol_size = legend_symbol_size, + background_color = background_color, + axis_text = axis_text, + axis_title = axis_title, + show_plot = show_plot, + return_plot = return_plot, + save_plot = save_plot, + save_param = save_param, + default_save_name = default_save_name) @@ -1584,53 +1602,53 @@ dimPlot2D = function(gobject, cell_ids = subset_cell_IDs) pl = .dimPlot2D_single(gobject = temp_gobject, - spat_unit = spat_unit, - feat_type = feat_type, - dim_reduction_to_use = dim_reduction_to_use, - dim_reduction_name = dim_reduction_name, - dim1_to_use = dim1_to_use, - dim2_to_use = dim2_to_use, - spat_enr_names = spat_enr_names, - show_NN_network = show_NN_network, - nn_network_to_use = nn_network_to_use, - network_name = network_name, - cell_color = cell_color, - cell_color_code = cell_color_code, - color_as_factor = color_as_factor, - cell_color_gradient = cell_color_gradient, - gradient_midpoint = gradient_midpoint, - gradient_style = gradient_style, - gradient_limits = gradient_limits, - select_cell_groups = select_cell_groups, - select_cells = select_cells, - show_other_cells = show_other_cells, - other_cell_color = other_cell_color, - other_point_size = other_point_size, - show_cluster_center = show_cluster_center, - show_center_label = show_center_label, - center_point_size = center_point_size, - center_point_border_col = center_point_border_col, - center_point_border_stroke = center_point_border_stroke, - label_size = label_size, - label_fontface = label_fontface, - edge_alpha = edge_alpha, - point_shape = point_shape, - point_size = point_size, - point_alpha = point_alpha, - point_border_col = point_border_col, - point_border_stroke = point_border_stroke, - title = group, - show_legend = show_legend, - legend_text = legend_text, - legend_symbol_size = legend_symbol_size, - background_color = background_color, - axis_text = axis_text, - axis_title = axis_title, - show_plot = FALSE, - return_plot = TRUE, - save_plot = FALSE, - save_param = list(), - default_save_name = default_save_name) + spat_unit = spat_unit, + feat_type = feat_type, + dim_reduction_to_use = dim_reduction_to_use, + dim_reduction_name = dim_reduction_name, + dim1_to_use = dim1_to_use, + dim2_to_use = dim2_to_use, + spat_enr_names = spat_enr_names, + show_NN_network = show_NN_network, + nn_network_to_use = nn_network_to_use, + network_name = network_name, + cell_color = cell_color, + cell_color_code = cell_color_code, + color_as_factor = color_as_factor, + cell_color_gradient = cell_color_gradient, + gradient_midpoint = gradient_midpoint, + gradient_style = gradient_style, + gradient_limits = gradient_limits, + select_cell_groups = select_cell_groups, + select_cells = select_cells, + show_other_cells = show_other_cells, + other_cell_color = other_cell_color, + other_point_size = other_point_size, + show_cluster_center = show_cluster_center, + show_center_label = show_center_label, + center_point_size = center_point_size, + center_point_border_col = center_point_border_col, + center_point_border_stroke = center_point_border_stroke, + label_size = label_size, + label_fontface = label_fontface, + edge_alpha = edge_alpha, + point_shape = point_shape, + point_size = point_size, + point_alpha = point_alpha, + point_border_col = point_border_col, + point_border_stroke = point_border_stroke, + title = group, + show_legend = show_legend, + legend_text = legend_text, + legend_symbol_size = legend_symbol_size, + background_color = background_color, + axis_text = axis_text, + axis_title = axis_title, + show_plot = FALSE, + return_plot = TRUE, + save_plot = FALSE, + save_param = list(), + default_save_name = default_save_name) savelist[[group_id]] <- pl @@ -4251,30 +4269,30 @@ spatDimCellPlot = function(...) { #' @return plotly object #' @keywords internal .dimPlot_2d_plotly <- function(gobject, - spat_unit = NULL, - feat_type = NULL, - dim_reduction_to_use = 'umap', - dim_reduction_name = 'umap', - dim1_to_use = 1, - dim2_to_use = 2, - spat_enr_names = NULL, - select_cell_groups = NULL, - select_cells = NULL, - show_other_cells = T, - other_cell_color = 'lightgrey', - other_point_size = 0.5, - show_NN_network = F, - nn_network_to_use = 'sNN', - network_name = 'sNN.pca', - color_as_factor = T, - cell_color = NULL, - cell_color_code = NULL, - show_cluster_center = F, - show_center_label = T, - center_point_size = 4, - label_size = 4, - edge_alpha = NULL, - point_size = 5){ + spat_unit = NULL, + feat_type = NULL, + dim_reduction_to_use = 'umap', + dim_reduction_name = 'umap', + dim1_to_use = 1, + dim2_to_use = 2, + spat_enr_names = NULL, + select_cell_groups = NULL, + select_cells = NULL, + show_other_cells = T, + other_cell_color = 'lightgrey', + other_point_size = 0.5, + show_NN_network = F, + nn_network_to_use = 'sNN', + network_name = 'sNN.pca', + color_as_factor = T, + cell_color = NULL, + cell_color_code = NULL, + show_cluster_center = F, + show_center_label = T, + center_point_size = 4, + label_size = 4, + edge_alpha = NULL, + point_size = 5){ # Set feat_type and spat_unit @@ -4514,33 +4532,33 @@ spatDimCellPlot = function(...) { #' @return plotly object #' @keywords internal .dimPlot_3d_plotly <- function(gobject, - spat_unit = NULL, - feat_type = NULL, - dim_reduction_to_use = 'umap', - dim_reduction_name = 'umap', - dim1_to_use = 1, - dim2_to_use = 2, - dim3_to_use = 3, - spat_enr_names = NULL, - - select_cell_groups = NULL, - select_cells = NULL, - show_other_cells = T, - other_cell_color = 'lightgrey', - other_point_size = 0.5, - - show_NN_network = F, - nn_network_to_use = 'sNN', - network_name = 'sNN.pca', - color_as_factor = T, - cell_color = NULL, - cell_color_code = NULL, - show_cluster_center = F, - show_center_label = T, - center_point_size = 4, - label_size = 4, - edge_alpha = NULL, - point_size = 1){ + spat_unit = NULL, + feat_type = NULL, + dim_reduction_to_use = 'umap', + dim_reduction_name = 'umap', + dim1_to_use = 1, + dim2_to_use = 2, + dim3_to_use = 3, + spat_enr_names = NULL, + + select_cell_groups = NULL, + select_cells = NULL, + show_other_cells = T, + other_cell_color = 'lightgrey', + other_point_size = 0.5, + + show_NN_network = F, + nn_network_to_use = 'sNN', + network_name = 'sNN.pca', + color_as_factor = T, + cell_color = NULL, + cell_color_code = NULL, + show_cluster_center = F, + show_center_label = T, + center_point_size = 4, + label_size = 4, + edge_alpha = NULL, + point_size = 1){ @@ -4832,64 +4850,64 @@ dimPlot3D = function(gobject, cat('create 2D plot\n') pl = .dimPlot_2d_plotly(gobject = gobject, - spat_unit = spat_unit, - feat_type = feat_type, - dim_reduction_to_use = dim_reduction_to_use, - dim_reduction_name = dim_reduction_name, - dim1_to_use = dim1_to_use, - dim2_to_use = dim2_to_use, - spat_enr_names = spat_enr_names, + spat_unit = spat_unit, + feat_type = feat_type, + dim_reduction_to_use = dim_reduction_to_use, + dim_reduction_name = dim_reduction_name, + dim1_to_use = dim1_to_use, + dim2_to_use = dim2_to_use, + spat_enr_names = spat_enr_names, - select_cell_groups = select_cell_groups, - select_cells = select_cells, - show_other_cells = show_other_cells, - other_cell_color = other_cell_color, - other_point_size = other_point_size, - - show_NN_network = show_NN_network, - nn_network_to_use = nn_network_to_use, - network_name = network_name, - color_as_factor = color_as_factor, - cell_color = cell_color, - cell_color_code = cell_color_code, - show_cluster_center = show_cluster_center, - show_center_label = show_center_label, - center_point_size = center_point_size, - label_size = label_size, - edge_alpha = edge_alpha, - point_size = point_size) + select_cell_groups = select_cell_groups, + select_cells = select_cells, + show_other_cells = show_other_cells, + other_cell_color = other_cell_color, + other_point_size = other_point_size, + + show_NN_network = show_NN_network, + nn_network_to_use = nn_network_to_use, + network_name = network_name, + color_as_factor = color_as_factor, + cell_color = cell_color, + cell_color_code = cell_color_code, + show_cluster_center = show_cluster_center, + show_center_label = show_center_label, + center_point_size = center_point_size, + label_size = label_size, + edge_alpha = edge_alpha, + point_size = point_size) } else{ cat('create 3D plot\n') pl = .dimPlot_3d_plotly(gobject = gobject, - spat_unit = spat_unit, - feat_type = feat_type, - dim_reduction_to_use = dim_reduction_to_use, - dim_reduction_name = dim_reduction_name, - dim1_to_use = dim1_to_use, - dim2_to_use = dim2_to_use, - dim3_to_use = dim3_to_use, - spat_enr_names = spat_enr_names, + spat_unit = spat_unit, + feat_type = feat_type, + dim_reduction_to_use = dim_reduction_to_use, + dim_reduction_name = dim_reduction_name, + dim1_to_use = dim1_to_use, + dim2_to_use = dim2_to_use, + dim3_to_use = dim3_to_use, + spat_enr_names = spat_enr_names, - select_cell_groups = select_cell_groups, - select_cells = select_cells, - show_other_cells = show_other_cells, - other_cell_color = other_cell_color, - other_point_size = other_point_size, + select_cell_groups = select_cell_groups, + select_cells = select_cells, + show_other_cells = show_other_cells, + other_cell_color = other_cell_color, + other_point_size = other_point_size, - show_NN_network = show_NN_network, - nn_network_to_use = nn_network_to_use, - network_name = network_name, - color_as_factor = color_as_factor, - cell_color = cell_color, - cell_color_code = cell_color_code, - show_cluster_center = show_cluster_center, - show_center_label = show_center_label, - center_point_size = center_point_size, - label_size = label_size, - edge_alpha = edge_alpha, - point_size = point_size) + show_NN_network = show_NN_network, + nn_network_to_use = nn_network_to_use, + network_name = network_name, + color_as_factor = color_as_factor, + cell_color = cell_color, + cell_color_code = cell_color_code, + show_cluster_center = show_cluster_center, + show_center_label = show_center_label, + center_point_size = center_point_size, + label_size = label_size, + edge_alpha = edge_alpha, + point_size = point_size) } @@ -5002,36 +5020,36 @@ plotPCA_3D = function(gobject, #' @return plotly object #' @keywords internal .spatPlot_2d_plotly = function(gobject, - spat_unit = NULL, - feat_type = NULL, - spat_loc_name = 'raw', - sdimx = NULL, - sdimy = NULL, - spat_enr_names = NULL, - point_size = 3, - cell_color = NULL, - cell_color_code = NULL, - color_as_factor = T, - select_cell_groups = NULL, - select_cells = NULL, - show_other_cells = T, - other_cell_color = "lightgrey", - other_point_size = 0.5, - show_network = FALSE, - spatial_network_name = 'spatial_network', - network_color = "lightgray", - network_alpha = 1, - other_cell_alpha = 0.5, - show_grid = FALSE, - spatial_grid_name = 'spatial_grid', - grid_color = NULL, - grid_alpha = 1, - show_legend = T, - axis_scale = c("cube","real","custom"), - custom_ratio = NULL, - x_ticks = NULL, - y_ticks = NULL, - show_plot = F) { + spat_unit = NULL, + feat_type = NULL, + spat_loc_name = 'raw', + sdimx = NULL, + sdimy = NULL, + spat_enr_names = NULL, + point_size = 3, + cell_color = NULL, + cell_color_code = NULL, + color_as_factor = T, + select_cell_groups = NULL, + select_cells = NULL, + show_other_cells = T, + other_cell_color = "lightgrey", + other_point_size = 0.5, + show_network = FALSE, + spatial_network_name = 'spatial_network', + network_color = "lightgray", + network_alpha = 1, + other_cell_alpha = 0.5, + show_grid = FALSE, + spatial_grid_name = 'spatial_grid', + grid_color = NULL, + grid_alpha = 1, + show_legend = T, + axis_scale = c("cube","real","custom"), + custom_ratio = NULL, + x_ticks = NULL, + y_ticks = NULL, + show_plot = F) { # Set feat_type and spat_unit spat_unit = set_default_spat_unit(gobject = gobject, @@ -5253,36 +5271,36 @@ plotPCA_3D = function(gobject, #' @return plotly object #' @keywords internal .spatPlot_3d_plotly = function(gobject, - spat_unit = NULL, - feat_type = NULL, - spat_loc_name = 'raw', - sdimx = NULL, - sdimy = NULL, - sdimz = NULL, - spat_enr_names = NULL, - point_size = 3, - cell_color = NULL, - cell_color_code = NULL, - select_cell_groups = NULL, - select_cells = NULL, - show_other_cells = T, - other_cell_color = "lightgrey", - other_point_size = 0.5, - show_network = FALSE, - spatial_network_name = 'spatial_network', - network_color = NULL, - network_alpha = 1, - other_cell_alpha = 0.5, - show_grid = FALSE, - spatial_grid_name = 'spatial_grid', - title = '', - show_legend = TRUE, - axis_scale = c("cube","real","custom"), - custom_ratio = NULL, - x_ticks = NULL, - y_ticks = NULL, - z_ticks = NULL, - show_plot = FALSE) { + spat_unit = NULL, + feat_type = NULL, + spat_loc_name = 'raw', + sdimx = NULL, + sdimy = NULL, + sdimz = NULL, + spat_enr_names = NULL, + point_size = 3, + cell_color = NULL, + cell_color_code = NULL, + select_cell_groups = NULL, + select_cells = NULL, + show_other_cells = T, + other_cell_color = "lightgrey", + other_point_size = 0.5, + show_network = FALSE, + spatial_network_name = 'spatial_network', + network_color = NULL, + network_alpha = 1, + other_cell_alpha = 0.5, + show_grid = FALSE, + spatial_grid_name = 'spatial_grid', + title = '', + show_legend = TRUE, + axis_scale = c("cube","real","custom"), + custom_ratio = NULL, + x_ticks = NULL, + y_ticks = NULL, + z_ticks = NULL, + show_plot = FALSE) { # Set feat_type and spat_unit @@ -5523,64 +5541,64 @@ spatPlot3D = function(gobject, cat('create 2D plot\n') pl = .spatPlot_2d_plotly(gobject = gobject, - spat_unit = spat_unit, - feat_type = feat_type, - sdimx = sdimx, - sdimy = sdimy, - point_size = point_size, - cell_color = cell_color, - cell_color_code = cell_color_code, - select_cell_groups = select_cell_groups, - select_cells = select_cells, - show_other_cells = show_other_cells, - other_cell_color = other_cell_color, - other_point_size =other_point_size, - show_network = show_network, - network_color = network_color, - network_alpha = network_alpha, - other_cell_alpha =other_cell_alpha, - spatial_network_name = spatial_network_name, - show_grid = show_grid, - grid_color = grid_color, - grid_alpha = grid_alpha, - spatial_grid_name = spatial_grid_name, - show_legend = show_legend, - axis_scale = axis_scale, - custom_ratio = custom_ratio, - x_ticks = x_ticks, - y_ticks = y_ticks, - show_plot = F) + spat_unit = spat_unit, + feat_type = feat_type, + sdimx = sdimx, + sdimy = sdimy, + point_size = point_size, + cell_color = cell_color, + cell_color_code = cell_color_code, + select_cell_groups = select_cell_groups, + select_cells = select_cells, + show_other_cells = show_other_cells, + other_cell_color = other_cell_color, + other_point_size =other_point_size, + show_network = show_network, + network_color = network_color, + network_alpha = network_alpha, + other_cell_alpha =other_cell_alpha, + spatial_network_name = spatial_network_name, + show_grid = show_grid, + grid_color = grid_color, + grid_alpha = grid_alpha, + spatial_grid_name = spatial_grid_name, + show_legend = show_legend, + axis_scale = axis_scale, + custom_ratio = custom_ratio, + x_ticks = x_ticks, + y_ticks = y_ticks, + show_plot = F) } else{ cat('create 3D plot\n') pl = .spatPlot_3d_plotly(gobject = gobject, - spat_unit = spat_unit, - feat_type = feat_type, - sdimx = sdimx, - sdimy = sdimy, - sdimz = sdimz, - point_size = point_size, - cell_color = cell_color, - cell_color_code = cell_color_code, - select_cell_groups = select_cell_groups, - select_cells = select_cells, - show_other_cells = show_other_cells, - other_cell_color = other_cell_color, - other_point_size =other_point_size, - show_network = show_network, - network_color = network_color, - network_alpha = network_alpha, - other_cell_alpha =other_cell_alpha, - spatial_network_name = spatial_network_name, - spatial_grid_name = spatial_grid_name, - show_legend = show_legend, - axis_scale = axis_scale, - custom_ratio = custom_ratio, - x_ticks = x_ticks, - y_ticks = y_ticks, - z_ticks = z_ticks, - show_plot = F) + spat_unit = spat_unit, + feat_type = feat_type, + sdimx = sdimx, + sdimy = sdimy, + sdimz = sdimz, + point_size = point_size, + cell_color = cell_color, + cell_color_code = cell_color_code, + select_cell_groups = select_cell_groups, + select_cells = select_cells, + show_other_cells = show_other_cells, + other_cell_color = other_cell_color, + other_point_size =other_point_size, + show_network = show_network, + network_color = network_color, + network_alpha = network_alpha, + other_cell_alpha =other_cell_alpha, + spatial_network_name = spatial_network_name, + spatial_grid_name = spatial_grid_name, + show_legend = show_legend, + axis_scale = axis_scale, + custom_ratio = custom_ratio, + x_ticks = x_ticks, + y_ticks = y_ticks, + z_ticks = z_ticks, + show_plot = F) } show_plot = ifelse(is.na(show_plot), readGiottoInstructions(gobject, param = 'show_plot'), show_plot) diff --git a/man/gg_annotation_raster.Rd b/man/gg_annotation_raster.Rd new file mode 100644 index 0000000..36f7ebb --- /dev/null +++ b/man/gg_annotation_raster.Rd @@ -0,0 +1,27 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/gg_annotation_raster.R +\name{gg_annotation_raster} +\alias{gg_annotation_raster} +\alias{gg_annotation_raster,gg,list-method} +\alias{gg_annotation_raster,gg,giottoImage-method} +\alias{gg_annotation_raster,gg,giottoLargeImage-method} +\title{Append image to ggplot as annotation_raster} +\usage{ +\S4method{gg_annotation_raster}{gg,list}(ggobj, gimage, ...) + +\S4method{gg_annotation_raster}{gg,giottoImage}(ggobj, gimage, ...) + +\S4method{gg_annotation_raster}{gg,giottoLargeImage}(ggobj, gimage, ...) +} +\arguments{ +\item{gimage}{\code{giottoLargeImage}, \code{giottoImage} or \code{list} thereof} + +\item{gg}{ggplot2 gg object} +} +\value{ +\code{gg} object with images to plot appended as annotation rasters +} +\description{ +Append image to ggplot as annotation_raster +} +\keyword{internal} From 7f2432c2ea1e724a9fde084710fce7c20cfdba43 Mon Sep 17 00:00:00 2001 From: jiajic <72078254+jiajic@users.noreply.github.com> Date: Thu, 25 Jan 2024 23:30:02 -0500 Subject: [PATCH 2/2] chore: doc updates --- R/gg_annotation_raster.R | 2 +- man/gg_annotation_raster.Rd | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/R/gg_annotation_raster.R b/R/gg_annotation_raster.R index ad37514..978b379 100644 --- a/R/gg_annotation_raster.R +++ b/R/gg_annotation_raster.R @@ -2,7 +2,7 @@ #' @name gg_annotation_raster #' @keywords internal #' @title Append image to ggplot as annotation_raster -#' @param ggobj ggplot2 gg object +#' @param ggobj ggplot2 `gg` object #' @param gimage `giottoLargeImage`, `giottoImage` or `list` thereof #' @return `gg` object with images to plot appended as annotation rasters NULL diff --git a/man/gg_annotation_raster.Rd b/man/gg_annotation_raster.Rd index 36f7ebb..7e5f574 100644 --- a/man/gg_annotation_raster.Rd +++ b/man/gg_annotation_raster.Rd @@ -14,9 +14,9 @@ \S4method{gg_annotation_raster}{gg,giottoLargeImage}(ggobj, gimage, ...) } \arguments{ -\item{gimage}{\code{giottoLargeImage}, \code{giottoImage} or \code{list} thereof} +\item{ggobj}{ggplot2 \code{gg} object} -\item{gg}{ggplot2 gg object} +\item{gimage}{\code{giottoLargeImage}, \code{giottoImage} or \code{list} thereof} } \value{ \code{gg} object with images to plot appended as annotation rasters