Skip to content

Commit d754728

Browse files
committed
Add new shading for targets
1 parent 134b53b commit d754728

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

R/splnr_featureRep.R

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ splnr_get_featureRep <- function(soln, pDat, targets = NA,
180180
#' pDat = pDat
181181
#' )
182182
#'
183-
#' (splnr_plot_featureRep(df, category = dat_category))
183+
#' (splnr_plot_featureRep(df, category = dat_category, showTarget = TRUE))
184184
#'
185185
splnr_plot_featureRep <- function(df,
186186
category = NA,
@@ -260,28 +260,33 @@ splnr_plot_featureRep <- function(df,
260260

261261

262262
gg_target <- ggplot2::ggplot() +
263-
ggplot2::geom_bar(data = df %>% dplyr::mutate(relative_held = dplyr::if_else(incidental == TRUE, NA, relative_held)), stat = "identity", position = "identity", ggplot2::aes(x = .data$feature, y = .data$relative_held, fill = .data$category), na.rm = TRUE) +
263+
ggplot2::geom_bar(data = df %>% dplyr::mutate(relative_held = dplyr::if_else(incidental == TRUE, NA, relative_held)),
264+
stat = "identity", position = "identity", ggplot2::aes(x = .data$feature, y = .data$relative_held,
265+
fill = .data$category, colour = .data$category),
266+
na.rm = TRUE) +
264267
ggplot2::geom_bar(data = df %>% dplyr::mutate(relative_held = dplyr::if_else(incidental == FALSE, NA, relative_held)),
265268
stat = "identity", position = "identity",
266269
ggplot2::aes(x = .data$feature, y = .data$relative_held), na.rm = TRUE, fill = "NA", colour = "black") +
267270
ggplot2::labs(title = plotTitle, x = "Feature", y = "Representation of features \nin total selected area (%)") +
268271
ggplot2::theme_bw() +
269272
ggplot2::scale_y_continuous(limits = c(0, ymax <- max(df$relative_held, na.rm = TRUE) + 10), expand = c(0, 0)) + # only works for min shortfall without incidental yet
270273
ggplot2::scale_fill_manual(
274+
aesthetics = c("fill", "colour"),
271275
values = colr,
272276
guide = ggplot2::guide_legend(nrow = nr)
273277
) +
278+
ggplot2::guides(colour = "none") +
274279
ggplot2::theme(
275280
axis.text.x = ggplot2::element_text(angle = 90, hjust = 1, vjust = 0.5, size = 16, colour = "black"),
276281
axis.text.y = ggplot2::element_text(size = 16, colour = "black"),
277282
axis.title.x = ggplot2::element_blank(),
278283
axis.title.y = ggplot2::element_text(size = 16),
279284
legend.title = ggplot2::element_blank(),
280285
legend.text = ggplot2::element_text(size = 16),
281-
legend.position = "inside",
286+
legend.position = "top",
282287
# legend.margin = ggplot2::margin(0, 0, 0, 0),
283288
# legend.justification.top = "centre",
284-
legend.position.inside = c(0.5, 0.92),
289+
# legend.position.inside = c(0.5, 0.92),
285290
legend.direction = "horizontal",
286291
legend.background = ggplot2::element_rect(fill = "NA"),
287292
title = ggplot2::element_text(size = 16),
@@ -290,7 +295,10 @@ splnr_plot_featureRep <- function(df,
290295

291296
if (!(is.na(showTarget))) {
292297
gg_target <- gg_target +
293-
ggplot2::geom_point(data = df, ggplot2::aes(x = .data$feature, y = .data$target), shape = 3, size = 10, na.rm = TRUE)
298+
299+
ggplot2::geom_bar(data = df %>% dplyr::mutate(relative_held = dplyr::if_else(incidental == TRUE, NA, relative_held)),
300+
stat = "identity", position = "identity", ggplot2::aes(x = .data$feature, y = .data$target), na.rm = TRUE,
301+
alpha = 0.3, colour = "grey50", fill = "white")
294302
}
295303

296304
return(gg_target)

0 commit comments

Comments
 (0)