Skip to content

Commit

Permalink
Minor changes to avoid warnings from ggplot2/tidyselect
Browse files Browse the repository at this point in the history
Increase ggplot2 requirement to >= 3.4.0
  • Loading branch information
lazappi committed Oct 24, 2023
1 parent 35a4bb0 commit dfab864
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 103 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: clustree
Type: Package
Title: Visualise Clusterings at Different Resolutions
Version: 0.5.0.9000
Version: 0.5.0.9001
Date: 2023-10-24
Authors@R:
c(person("Luke", "Zappia", role = c("aut", "cre"),
Expand Down Expand Up @@ -33,7 +33,7 @@ Imports: checkmate,
igraph,
dplyr,
grid,
ggplot2,
ggplot2 (>= 3.4.0),
viridis,
methods,
rlang,
Expand Down
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# clustree (development version)

### _clustree_ 0.5.0.9001 (2023-10-24)

* Avoid warnings due to deprecated functionality in _ggplot2_ and
_tidyselect_ (Fixes #35)

### _clustree_ 0.5.0.9000 (2023-10-24)

* Minor updates for compatibility with upcoming _Seurat_ v5 release (Fixes #93)
Expand Down
49 changes: 25 additions & 24 deletions R/clustree.R
Original file line number Diff line number Diff line change
Expand Up @@ -284,13 +284,14 @@ clustree.matrix <- function(x, prefix,
ends = edge_arrow_ends),
end_cap = circle(circle_size_end, "points"),
start_cap = circle(circle_size_start, "points"),
aes_(colour = ~count,
alpha = ~in_prop,
edge_width = ~is_core))
aes(colour = .data$count,
alpha = .data$in_prop,
edge_width = .data$is_core))

} else {
gg <- gg + geom_edge_link(aes_(colour = ~count, alpha = ~in_prop,
edge_width = ~is_core))
gg <- gg + geom_edge_link(aes(colour = .data$count,
alpha = .data$in_prop,
edge_width = .data$is_core))
}

if (highlight_core) {
Expand All @@ -311,17 +312,17 @@ clustree.matrix <- function(x, prefix,

# Plot node text
if (scale_node_text && !is.numeric(node_size)) {
gg <- gg + geom_node_text(aes_(label = ~cluster,
size = as.name(graph_attr$node_size)),
gg <- gg + geom_node_text(aes(label = .data$cluster,
size = .data[[graph_attr$node_size]]),
colour = node_text_colour,
angle = node_text_angle
)
} else {
gg <- gg + geom_node_text(aes_(label = ~cluster),
gg <- gg + geom_node_text(aes(label = .data$cluster),
size = node_text_size,
colour = node_text_colour,
angle = node_text_angle
)
)
}

if (!(is.null(node_label))) {
Expand Down Expand Up @@ -560,25 +561,25 @@ add_node_points <- function(node_colour, node_size, node_alpha, allowed) {
}

switch(aes_allowed,
col_size_alpha = geom_node_point(aes_(colour = as.name(node_colour),
size = as.name(node_size),
alpha = as.name(node_alpha))),
col_alpha = geom_node_point(aes_(colour = as.name(node_colour),
alpha = as.name(node_alpha)),
col_size_alpha = geom_node_point(aes(colour = .data[[node_colour]],
size = .data[[node_size]],
alpha = .data[[node_alpha]])),
col_alpha = geom_node_point(aes(colour = .data[[node_colour]],
alpha = .data[[node_alpha]]),
size = node_size),
col_size = geom_node_point(aes_(colour = as.name(node_colour),
size = as.name(node_size)),
col_size = geom_node_point(aes(colour = .data[[node_colour]],
size = .data[[node_size]]),
alpha = node_alpha),
col = geom_node_point(aes_(colour = as.name(node_colour)),
col = geom_node_point(aes(colour = .data[[node_colour]]),
size = node_size,
alpha = node_alpha),
size_alpha = geom_node_point(aes_(size = as.name(node_size),
alpha = as.name(node_alpha)),
size_alpha = geom_node_point(aes(size = .data[[node_size]],
alpha = .data[[node_alpha]]),
colour = node_colour),
size = geom_node_point(aes_(size = as.name(node_size)),
size = geom_node_point(aes(size = .data[[node_size]]),
colour = node_colour,
alpha = node_alpha),
alpha = geom_node_point(aes_(alpha = as.name(node_alpha)),
alpha = geom_node_point(aes(alpha = .data[[node_alpha]]),
colour = node_colour,
size = node_size),
none = geom_node_point(colour = node_colour,
Expand Down Expand Up @@ -610,13 +611,13 @@ add_node_labels <- function(node_label, node_colour, node_label_size,
is_allowed <- c(node_colour) %in% allowed

if (is_allowed) {
geom_node_label(aes_(label = as.name(node_label),
fill = as.name(node_colour)),
geom_node_label(aes(label = .data[[node_label]],
fill = .data[[node_colour]]),
size = node_label_size,
colour = node_label_colour,
nudge_y = node_label_nudge)
} else {
geom_node_label(aes_(label = as.name(node_label)),
geom_node_label(aes(label = .data[[node_label]]),
fill = node_colour,
size = node_label_size,
colour = node_label_colour,
Expand Down
139 changes: 69 additions & 70 deletions R/clustree_overlay.R
Original file line number Diff line number Diff line change
Expand Up @@ -259,12 +259,12 @@ clustree_overlay.matrix <- function(x, prefix, metadata, x_value, y_value,
levels(edges[[paste0("from_", prefix)]]) <- levels(nodes[[prefix]])

if (use_colour == "points") {
gg <- ggplot(points, aes_(x = as.name(x_value), y = as.name(y_value))) +
geom_point(aes_(colour = as.name(paste0(hi_res, "_cluster"))),
gg <- ggplot(points, aes(x = .data[[x_value]], y = .data[[y_value]])) +
geom_point(aes(colour = .data[[paste0(hi_res, "_cluster")]]),
size = point_size, alpha = point_alpha,
shape = point_shape)
} else {
gg <- ggplot(points, aes_(x = as.name(x_value), y = as.name(y_value))) +
gg <- ggplot(points, aes(x = .data[[x_value]], y = .data[[y_value]])) +
geom_point(colour = alt_colour, size = point_size,
alpha = point_alpha, shape = point_shape)
}
Expand All @@ -283,36 +283,36 @@ clustree_overlay.matrix <- function(x, prefix, metadata, x_value, y_value,
if (use_colour == "edges") {
gg <- gg +
geom_segment(data = edges_res,
aes_(x = as.name(paste0("from_", x_value)),
y = as.name(paste0("from_", y_value)),
xend = as.name(paste0("to_", x_value)),
yend = as.name(paste0("to_", y_value)),
alpha = ~ in_prop,
colour = as.name(paste0("from_", prefix))),
aes(x = .data[[paste0("from_", x_value)]],
y = .data[[paste0("from_", y_value)]],
xend = .data[[paste0("to_", x_value)]],
yend = .data[[paste0("to_", y_value)]],
alpha = .data$in_prop,
colour = .data[[paste0("from_", prefix)]]),
arrow = arrow(length = unit(edge_width * 5,
"points")),
size = edge_width)
linewidth = edge_width)
} else {
gg <- gg +
geom_segment(data = edges_res,
aes_(x = as.name(paste0("from_", x_value)),
y = as.name(paste0("from_", y_value)),
xend = as.name(paste0("to_", x_value)),
yend = as.name(paste0("to_", y_value)),
alpha = ~ in_prop),
aes(x = .data[[paste0("from_", x_value)]],
y = .data[[paste0("from_", y_value)]],
xend = .data[[paste0("to_", x_value)]],
yend = .data[[paste0("to_", y_value)]],
alpha = .data$in_prop),
arrow = arrow(length = unit(edge_width * 5,
"points")),
size = edge_width,
linewidth = edge_width,
colour = alt_colour)
}
}

if (label_nodes) {
gg <- gg +
ggrepel::geom_label_repel(data = nodes,
aes_(x = as.name(x_val),
y = as.name(y_val),
label = ~ node),
aes(x = .data[[x_val]],
y = .data[[y_val]],
label = .data$node),
size = label_size)
}

Expand Down Expand Up @@ -658,57 +658,57 @@ overlay_node_points <- function(nodes, x_value, y_value, node_colour, node_size,

switch(aes_allowed,
col_size_alpha = geom_point(data = nodes,
aes_(x = as.name(x_value),
y = as.name(y_value),
fill = as.name(node_colour),
size = as.name(node_size),
alpha = as.name(node_alpha)),
aes(x = .data[[x_value]],
y = .data[[y_value]],
fill = .data[[node_colour]],
size = .data[[node_size]],
alpha = .data[[node_alpha]]),
shape = 21),
col_alpha = geom_point(data = nodes,
aes_(x = as.name(x_value),
y = as.name(y_value),
fill = as.name(node_colour),
alpha = as.name(node_alpha)),
aes(x = .data[[x_value]],
y = .data[[y_value]],
fill = .data[[node_colour]],
alpha = .data[[node_alpha]]),
size = node_size,
shape = 21),
col_size = geom_point(data = nodes,
aes_(x = as.name(x_value),
y = as.name(y_value),
fill = as.name(node_colour),
size = as.name(node_size)),
aes(x = .data[[x_value]],
y = .data[[y_value]],
fill = .data[[node_colour]],
size = .data[[node_size]]),
alpha = node_alpha,
shape = 21),
col = geom_point(data = nodes,
aes_(x = as.name(x_value),
y = as.name(y_value),
fill = as.name(node_colour)),
aes(x = .data[[x_value]],
y = .data[[y_value]],
fill = .data[[node_colour]]),
size = node_size,
alpha = node_alpha,
shape = 21),
size_alpha = geom_point(data = nodes,
aes_(x = as.name(x_value),
y = as.name(y_value),
fill = as.name(node_size),
alpha = as.name(node_alpha)),
aes(x = .data[[x_value]],
y = .data[[y_value]],
fill = .data[[node_size]],
alpha = .data[[node_alpha]]),
colour = node_colour,
shape = 21),
size = geom_point(data = nodes,
aes_(x = as.name(x_value),
y = as.name(y_value),
size = as.name(node_size)),
aes(x = .data[[x_value]],
y = .data[[y_value]],
size = .data[[node_size]]),
fill = node_colour,
alpha = node_alpha,
shape = 21),
alpha = geom_point(data = nodes,
aes_(x = as.name(x_value),
y = as.name(y_value),
alpha = as.name(node_alpha)),
aes(x = .data[[x_value]],
y = .data[[y_value]],
alpha = .data[[node_alpha]]),
fill = node_colour,
size = node_size,
shape = 21),
none = geom_point(data = nodes,
aes_(x = as.name(x_value),
y = as.name(y_value)),
aes(x = .data[[x_value]],
y = .data[[y_value]]),
fill = node_colour,
size = node_size,
alpha = node_alpha,
Expand Down Expand Up @@ -776,14 +776,13 @@ plot_overlay_side <- function(nodes, edges, points, prefix, side_value,
!!as.name(paste0("to_", prefix)))))

if (use_colour == "points") {

gg <- ggplot(points, aes_(x = as.name(side_value), y = point_y)) +
geom_jitter(aes_(colour = as.name(colnames(points)[3])),
gg <- ggplot(points, aes(x = .data[[side_value]], y = point_y)) +
geom_jitter(aes(colour = .data[[colnames(points)[3]]]),
height = y_jitter * median(y_diffs), width = 0,
size = point_size, alpha = point_alpha,
shape = point_shape)
} else {
gg <- ggplot(points, aes_(x = as.name(side_value), y = point_y)) +
gg <- ggplot(points, aes(x = .data[[side_value]], y = point_y)) +
geom_jitter(height = y_jitter * median(y_diffs), width = 0,
colour = alt_colour, size = point_size,
alpha = point_alpha, shape = point_shape)
Expand All @@ -802,37 +801,37 @@ plot_overlay_side <- function(nodes, edges, points, prefix, side_value,
if (use_colour == "edges") {
gg <- gg +
geom_segment(data = edges_res,
aes_(x = as.name(paste0("from_", side_value)),
y = ~ from_y,
xend = as.name(paste0("to_", side_value)),
yend = ~ to_y,
alpha = ~ in_prop,
colour = as.name(paste0("from_", prefix))),
aes(x = .data[[paste0("from_", side_value)]],
y = .data$from_y,
xend = .data[[paste0("to_", side_value)]],
yend = .data$to_y,
alpha = .data$in_prop,
colour = .data[[paste0("from_", prefix)]]),
arrow = arrow(length = unit(edge_width * 5,
"points")),
size = edge_width)
linewidth = edge_width)
} else {
gg <- gg +
geom_segment(data = edges_res,
aes_(x = as.name(paste0("from_", side_value)),
y = ~ from_y,
xend = as.name(paste0("to_", side_value)),
yend = ~ to_y,
alpha = ~ in_prop),
aes(x = .data[[paste0("from_", side_value)]],
y = .data$from_y,
xend = .data[[paste0("to_", side_value)]],
yend = .data$to_y,
alpha = .data$in_prop),
arrow = arrow(length = unit(edge_width * 5,
"points")),
size = edge_width,
linewidth = edge_width,
colour = alt_colour)
}
}

if (label_nodes) {
gg <- gg +
ggrepel::geom_label_repel(data = nodes,
aes_(x = as.name(paste0("mean_",
side_value)),
y = ~ y,
label = ~ node),
aes(x = .data[[paste0("mean_",
side_value)]],
y = .data$y,
label = .data$node),
size = label_size)
}

Expand All @@ -843,8 +842,8 @@ plot_overlay_side <- function(nodes, edges, points, prefix, side_value,
scale_colour_hue(drop = FALSE) +
ylab(prefix) +
theme_minimal() +
theme(axis.line.x = element_line(size = 1, colour = "grey50"),
axis.ticks.x = element_line(size = 0.6, colour = "grey50"),
theme(axis.line.x = element_line(linewidth = 1, colour = "grey50"),
axis.ticks.x = element_line(linewidth = 0.6, colour = "grey50"),
panel.grid.major.x = element_blank(),
panel.grid.minor.x = element_blank(),
panel.grid.minor.y = element_blank())
Expand Down
Loading

0 comments on commit dfab864

Please sign in to comment.