Skip to content

Commit b3fdc13

Browse files
adjustments in histogram
1 parent 2ce2c1b commit b3fdc13

4 files changed

+26
-27
lines changed

R/sits_histogram.R

+17-18
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ hist.sits <- function(x, ...) {
2727
#' @description This is a generic function. Parameters depend on the specific
2828
#' type of input.
2929
#'
30-
#' @param object Object of classes "raster_cube".
30+
#' @param x Object of classes "raster_cube".
3131
#' @param ... Further specifications for \link{summary}.
3232
#' @param tile Tile to be shown
3333
#' @param date Date to be shown
3434
#' @param band Band to be shown
35-
#' @param size. Number of cells to be sampled
35+
#' @param size Number of cells to be sampled
3636
#'
3737
#' @return A histogram of one band of data cube.
3838
#'
@@ -124,7 +124,7 @@ hist.raster_cube <- function(x, ...,
124124
#' @description This is a generic function. Parameters depend on the specific
125125
#' type of input.
126126
#'
127-
#' @param object Object of classes "raster_cube".
127+
#' @param x Object of classes "raster_cube".
128128
#' @param ... Further specifications for \link{summary}.
129129
#' @param tile Tile to be shown
130130
#' @param label Label to be shown
@@ -153,8 +153,8 @@ hist.raster_cube <- function(x, ...,
153153
#' @export
154154
hist.probs_cube <- function(x, ...,
155155
tile = x[["tile"]][[1]],
156-
labels = NULL,
157-
size = 10000) {
156+
label = NULL,
157+
size = 100000) {
158158
.check_set_caller("sits_hist_raster_cube")
159159
# Pre-conditional check
160160
.check_chr_parameter(tile, allow_null = TRUE)
@@ -171,13 +171,13 @@ hist.probs_cube <- function(x, ...,
171171
# filter the tile to be processed
172172
tile <- .cube_filter_tiles(cube = x, tiles = tile)
173173
# check the labels
174-
if (.has(labels)) {
174+
if (.has(label)) {
175175
# is this a valid label?
176-
.check_that(labels %in% .tile_labels(tile),
176+
.check_that(label %in% .tile_labels(tile),
177177
msg = .conf("messages", "sits_hist_label")
178178
)
179179
} else {
180-
labels <- .tile_labels(tile)
180+
label <- .tile_labels(tile)[[1]]
181181
}
182182
# select the file to be plotted
183183
probs_file <- .tile_path(tile)
@@ -194,28 +194,27 @@ hist.probs_cube <- function(x, ...,
194194
# read file
195195
r <- terra::rast(probs_file)
196196
# select layer
197-
layers <- layers[labels]
197+
layers <- layers[label]
198198
values <- terra::spatSample(r[[layers]], size = size)
199199
values <- values * band_scale + band_offset
200-
colnames(values) <- labels
201-
colors_sits <- .colors_get(labels)
202-
values <- tidyr::pivot_longer(values, cols = dplyr::all_of(unname(labels)))
200+
colnames(values) <- label
201+
color_sits <- .colors_get(label)
203202
# values[["color"]] <- colors_sits[values[["name"]]]
204203
density_plot <-
205204
values |>
206-
ggplot2::ggplot(ggplot2::aes(x = .data[["value"]])) +
205+
ggplot2::ggplot(ggplot2::aes(x = .data[[label]])) +
207206
ggplot2::geom_density(
208-
ggplot2::aes(color = .data[["name"]],
209-
fill = .data[["name"]]),
207+
ggplot2::aes(x = .data[[label]]),
208+
color = color_sits,
209+
fill = color_sits,
210210
linewidth = 0.8,
211211
alpha = 0.50
212212
) +
213213
ggplot2::scale_x_continuous(limits = c(0.0, 1.0)) +
214214
ggplot2::xlab("Probability") +
215215
ggplot2::ylab("") +
216216
ggplot2::theme(legend.title = ggplot2::element_blank()) +
217-
ggplot2::ggtitle(paste("Distribution of probabilities for labels",
218-
paste(labels, collapse = ",")))
217+
ggplot2::ggtitle(paste("Distribution of probabilities for label", label))
219218

220219
return(suppressWarnings(density_plot))
221220
}
@@ -258,7 +257,7 @@ hist.probs_cube <- function(x, ...,
258257
hist.uncertainty_cube <- function(
259258
x, ...,
260259
tile = x[["tile"]][[1]],
261-
size = 10000) {
260+
size = 100000) {
262261
.check_set_caller("sits_hist_uncertainty_cube")
263262
# Pre-conditional check
264263
.check_chr_parameter(tile, allow_null = TRUE)

man/hist.probs_cube.Rd

+5-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/hist.raster_cube.Rd

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/hist.uncertainty_cube.Rd

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)