Skip to content

Commit

Permalink
Fixed CI warnings/errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
enblacar committed Jul 31, 2023
1 parent 03a86f8 commit b386002
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 142 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ Many (except a few selected cases) of the functions that returned list of differ
- `legend.text.face`: To control the style of the **legend text**.
- Changed default font style for legend text from `bold` to `plain`.
- Changed default font style for axis text from `bold` to `plain`.
- When using `plot.axes = TRUE` parameter in `SCpubr::do_DimPlot()`, `SCpubr::do_FeaturePlot()` and `SCpubr::do_NebulosaPlot()`, now the entirety of the X and Y axis is removed, titles included.
- Remove plot margin padding in `SCpubr::do_DimPlot()`, `SCpubr::do_FeaturePlot()` and `SCpubr::do_NebulosaPlot()`.

## `SCpubr::do_AlluvialPlot`
- Added `sequential.palette` and `sequential.direction` parameters.
Expand Down
76 changes: 29 additions & 47 deletions R/do_DimPlot.R
Original file line number Diff line number Diff line change
Expand Up @@ -487,9 +487,6 @@ do_DimPlot <- function(sample,
function_use = ggplot2::scale_fill_manual(values = colors.use.label.fill),
scale = "fill")

p <- add_scale(p = p[length(p$layers)],
function_use = ggplot2::scale_fill_manual(values = colors.use.label.fill),
scale = "fill")
}
p$layers[[length(p$layers)]]$aes_params$fontface <- "bold"
}
Expand Down Expand Up @@ -550,9 +547,12 @@ do_DimPlot <- function(sample,
min_y <- min(data$data[[1]]$y) * (1 + contour_expand_axes)
max_y <- max(data$data[[1]]$y) * (1 + contour_expand_axes)
# Expand axes limits to allocate the new contours.
p <- p +
ggplot2::xlim(c(min_x, max_x)) +
ggplot2::ylim(c(min_y, max_y))
suppressMessages({
p <- p +
ggplot2::xlim(c(min_x, max_x)) +
ggplot2::ylim(c(min_y, max_y))
})

}
} else if (isTRUE(group_by_and_split_by_used) | isTRUE(split_by_used)){
list.plots <- list()
Expand Down Expand Up @@ -670,9 +670,12 @@ do_DimPlot <- function(sample,
min_y <- min(data$data[[1]]$y) * (1 + contour_expand_axes)
max_y <- max(data$data[[1]]$y) * (1 + contour_expand_axes)
# Expand axes limits to allocate the new contours.
p.loop <- p.loop +
ggplot2::xlim(c(min_x, max_x)) +
ggplot2::ylim(c(min_y, max_y))
suppressMessages({
p.loop <- p.loop +
ggplot2::xlim(c(min_x, max_x)) +
ggplot2::ylim(c(min_y, max_y))
})

}

list.plots[[value]] <- p.loop
Expand Down Expand Up @@ -783,9 +786,11 @@ do_DimPlot <- function(sample,
min_y <- min(data$data[[1]]$y) * (1 + contour_expand_axes)
max_y <- max(data$data[[1]]$y) * (1 + contour_expand_axes)
# Expand axes limits to allocate the new contours.
p <- p +
ggplot2::xlim(c(min_x, max_x)) +
ggplot2::ylim(c(min_y, max_y))
suppressMessages({
p <- p +
ggplot2::xlim(c(min_x, max_x)) +
ggplot2::ylim(c(min_y, max_y))
})
}

}
Expand All @@ -805,7 +810,7 @@ do_DimPlot <- function(sample,
legend.title = if (legend.position != "none") {ggplot2::element_text(face = legend.title.face)} else {ggplot2::element_blank()},
legend.position = legend.position,
panel.grid = ggplot2::element_blank(),
plot.margin = ggplot2::margin(t = 10, r = 10, b = 10, l = 10),
plot.margin = ggplot2::margin(t = 0, r = 0, b = 0, l = 0),
plot.background = ggplot2::element_rect(fill = "white", color = "white"),
panel.background = ggplot2::element_rect(fill = "white", color = "white"),
legend.background = ggplot2::element_rect(fill = "white", color = "white"))
Expand Down Expand Up @@ -843,42 +848,19 @@ do_DimPlot <- function(sample,
ggplot2::labs(caption = plot.caption)
}
}

# For embeddings that are umap of tsne, we remove all axes.
if (reduction %in% c("umap", "tsne")){
# If dims is first and then second (most of the cases).
if (sum(dims == c(1, 2)) == 2){
# Remove axes completely.
p <- p &
ggplot2::theme(axis.title = if (base::isFALSE(plot.axes)){ggplot2::element_blank()} else {ggplot2::element_text(color = "black", face = axis.title.face, hjust = 0.5)},
axis.text = if (base::isFALSE(plot.axes)){ggplot2::element_blank()} else {ggplot2::element_text(color = "black", face = axis.text.face)},
axis.ticks = if (base::isFALSE(plot.axes)){ggplot2::element_blank()} else {ggplot2::element_line(color = "black")},
axis.line = if (base::isFALSE(plot.axes)){ggplot2::element_blank()} else {ggplot2::element_line(color = "black")})
# If dims do not follow the usual order.
} else {
# Get the name of the selected dims.
labels <- colnames(sample@reductions[[reduction]][[]])[dims]
# Remove everything in the axes but the axis titles.
p <- p &
ggplot2::theme(axis.text = if (base::isFALSE(plot.axes)){ggplot2::element_blank()} else {ggplot2::element_text(color = "black", face = axis.text.face)},
axis.ticks = if (base::isFALSE(plot.axes)){ggplot2::element_blank()} else {ggplot2::element_line(color = "black")},
axis.line =if (base::isFALSE(plot.axes)){ggplot2::element_blank()} else {ggplot2::element_line(color = "black")},
axis.title = ggplot2::element_text(face = axis.title.face, hjust = 0.5, color = "black")) &
ggplot2::xlab(labels[1]) &
ggplot2::ylab(labels[2])
}
# For diffusion maps, we do want to keep at least the axis titles so that we know which DC are we plotting.

if (base::isFALSE(plot.axes)){
p <- p &
ggplot2::theme(axis.title = ggplot2::element_blank(),
axis.text = ggplot2::element_blank(),
axis.ticks = ggplot2::element_blank(),
axis.line = ggplot2::element_blank())
} else {
# Get the name of the selected dims.
labels <- colnames(sample@reductions[[reduction]][[]])[dims]
# Remove everything in the axes but not the axis titles.
p <- p &
ggplot2::theme(axis.text = if (base::isFALSE(plot.axes)){ggplot2::element_blank()} else {ggplot2::element_text(color = "black", face = axis.text.face)},
axis.ticks = if (base::isFALSE(plot.axes)){ggplot2::element_blank()} else {ggplot2::element_line(color = "black")},
axis.line =if (base::isFALSE(plot.axes)){ggplot2::element_blank()} else {ggplot2::element_line(color = "black")},
axis.title = ggplot2::element_text(face = axis.title.face, hjust = 0.5, color = "black")) &
ggplot2::xlab(labels[1]) &
ggplot2::ylab(labels[2])
ggplot2::theme(axis.title = ggplot2::element_text(face = axis.title.face),
axis.text = ggplot2::element_text(face = axis.text.face),
axis.ticks = ggplot2::element_line(color = "black"),
axis.line = ggplot2::element_line(color = "black"))
}

# Add marginal plots.
Expand Down
79 changes: 28 additions & 51 deletions R/do_FeaturePlot.R
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ do_FeaturePlot <- function(sample,
# Add lengthy error messages.
withr::local_options(.new = list("warning.length" = 8170))

`%>%` <- magrittr::`%>%`
check_suggests(function_name = "do_FeaturePlot")
# Check if the sample provided is a Seurat object.
check_Seurat(sample = sample)
Expand Down Expand Up @@ -974,23 +973,23 @@ do_FeaturePlot <- function(sample,

# Fix the extra space and add theme parameters.
p <- p &
ggplot2::theme_minimal(base_size = font.size) &
ggplot2::theme(plot.margin = ggplot2::margin(t = 10, r = 10, b = 10, l = 10),
plot.title = ggplot2::element_text(face = plot.title.face,
hjust = ifelse(!(is.null(split.by)), 0.5, 0)),
plot.subtitle = ggplot2::element_text(face = plot.subtitle.face, hjust = 0),
plot.caption = ggplot2::element_text(face = plot.caption.face, hjust = 1),
panel.grid = ggplot2::element_blank(),
plot.title.position = "plot",
plot.caption.position = "plot",
text = ggplot2::element_text(family = font.type),
legend.position = legend.position,
legend.text = ggplot2::element_text(face = legend.text.face),
legend.title = ggplot2::element_text(face = legend.title.face),
legend.justification = "center",
plot.background = ggplot2::element_rect(fill = "white", color = "white"),
panel.background = ggplot2::element_rect(fill = "white", color = "white"),
legend.background = ggplot2::element_rect(fill = "white", color = "white"))
ggplot2::theme_minimal(base_size = font.size) &
ggplot2::theme(plot.margin = ggplot2::margin(t = 0, r = 0, b = 0, l = 0),
plot.title = ggplot2::element_text(face = plot.title.face,
hjust = ifelse(!(is.null(split.by)), 0.5, 0)),
plot.subtitle = ggplot2::element_text(face = plot.subtitle.face, hjust = 0),
plot.caption = ggplot2::element_text(face = plot.caption.face, hjust = 1),
panel.grid = ggplot2::element_blank(),
plot.title.position = "plot",
plot.caption.position = "plot",
text = ggplot2::element_text(family = font.type),
legend.position = legend.position,
legend.text = ggplot2::element_text(face = legend.text.face),
legend.title = ggplot2::element_text(face = legend.title.face),
legend.justification = "center",
plot.background = ggplot2::element_rect(fill = "white", color = "white"),
panel.background = ggplot2::element_rect(fill = "white", color = "white"),
legend.background = ggplot2::element_rect(fill = "white", color = "white"))
if (is.null(split.by) & legend.position != "none"){
counter <- 0
for (feature in features){
Expand Down Expand Up @@ -1076,35 +1075,18 @@ do_FeaturePlot <- function(sample,
}
}

# For embeddings that are umap of tsne, we remove all axes..
if (reduction %in% c("umap", "tsne")){
# if dims is first and then second.
if (sum(dims == c(1, 2)) == 2){
p <- p &
ggplot2::theme(axis.title = if (base::isFALSE(plot.axes)){ggplot2::element_blank()} else {ggplot2::element_text(color = "black", face = axis.title.face, hjust = 0.5)},
axis.text = if (base::isFALSE(plot.axes)){ggplot2::element_blank()} else {ggplot2::element_text(color = "black", face = axis.text.face)},
axis.ticks = if (base::isFALSE(plot.axes)){ggplot2::element_blank()} else {ggplot2::element_line(color = "black")},
axis.line =if (base::isFALSE(plot.axes)){ggplot2::element_blank()} else {ggplot2::element_line(color = "black")})
} else {
labels <- colnames(sample@reductions[[reduction]][[]])[dims]
p <- p &
ggplot2::theme(axis.text = if (base::isFALSE(plot.axes)){ggplot2::element_blank()} else {ggplot2::element_text(color = "black", face = axis.text.face)},
axis.ticks = if (base::isFALSE(plot.axes)){ggplot2::element_blank()} else {ggplot2::element_line(color = "black")},
axis.line = if (base::isFALSE(plot.axes)){ggplot2::element_blank()} else {ggplot2::element_line(color = "black")},
axis.title = ggplot2::element_text(face = axis.title.face, hjust = 0.5, color = "black")) &
ggplot2::xlab(labels[1]) &
ggplot2::ylab(labels[2])
}
# For diffusion maps, we do want to keep at least the axis titles so that we know which DC are we plotting.
if (base::isFALSE(plot.axes)){
p <- p &
ggplot2::theme(axis.title = ggplot2::element_blank(),
axis.text = ggplot2::element_blank(),
axis.ticks = ggplot2::element_blank(),
axis.line = ggplot2::element_blank())
} else {
labels <- colnames(sample@reductions[[reduction]][[]])[dims]
p <- p &
ggplot2::theme(axis.text = if (base::isFALSE(plot.axes)){ggplot2::element_blank()} else {ggplot2::element_text(color = "black", face = axis.text.face)},
axis.ticks = if (base::isFALSE(plot.axes)){ggplot2::element_blank()} else {ggplot2::element_line(color = "black")},
axis.line = if (base::isFALSE(plot.axes)){ggplot2::element_blank()} else {ggplot2::element_line(color = "black")},
axis.title = ggplot2::element_text(face = axis.title.face, hjust = 0.5, color = "black")) &
ggplot2::xlab(labels[1]) &
ggplot2::ylab(labels[2])
ggplot2::theme(axis.title = ggplot2::element_text(face = axis.title.face),
axis.text = ggplot2::element_text(face = axis.text.face),
axis.ticks = ggplot2::element_line(color = "black"),
axis.line = ggplot2::element_line(color = "black"))
}

# Further patch for diffusion maps.
Expand All @@ -1116,12 +1098,7 @@ do_FeaturePlot <- function(sample,
ggplot2::xlim(c(min(sample@reductions[[reduction]][[]][, labels[1]], na.rm = TRUE),
max(sample@reductions[[reduction]][[]][, labels[1]], na.rm = TRUE))) &
ggplot2::ylim(c(min(sample@reductions[[reduction]][[]][, labels[2]], na.rm = TRUE),
max(sample@reductions[[reduction]][[]][, labels[2]], na.rm = TRUE))) &
# Remove axis elements so that the axis title is the only thing left.
ggplot2::theme(axis.text = if (base::isFALSE(plot.axes)){ggplot2::element_blank()} else {ggplot2::element_text(color = "black", face = axis.text.face)},
axis.ticks = if (base::isFALSE(plot.axes)){ggplot2::element_blank()} else {ggplot2::element_line(color = "black")},
axis.line = if (base::isFALSE(plot.axes)){ggplot2::element_blank()} else {ggplot2::element_line(color = "black")},
axis.title = ggplot2::element_text(face = axis.title.face, hjust = 0.5, color = "black"))
max(sample@reductions[[reduction]][[]][, labels[2]], na.rm = TRUE)))
})

}
Expand Down
Loading

0 comments on commit b386002

Please sign in to comment.