Skip to content

Commit b6dffa9

Browse files
committed
update gheatmap to be compatible with ggplot2-4.0.0
1 parent 3798e55 commit b6dffa9

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

R/gheatmap.R

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ gheatmap <- function(p, data, offset=0, width=1, low="green", high="red", color=
104104
dd$variable <- factor(dd$variable, levels=colnames_level)
105105
}
106106
V2 <- start + as.numeric(dd$variable) * width
107-
mapping <- data.frame(from=dd$variable, to=V2)
108-
mapping <- unique(mapping)
107+
data_axis <- data.frame(from=dd$variable, to=V2)
108+
data_axis <- unique(data_axis)
109109

110110
dd$x <- V2
111111
dd$width <- width
@@ -127,25 +127,25 @@ gheatmap <- function(p, data, offset=0, width=1, low="green", high="red", color=
127127
} else {
128128
y <- max(p$data$y) + 1
129129
}
130-
mapping$y <- y
131-
mapping[[".panel"]] <- factor("Tree")
130+
data_axis$y <- y
131+
data_axis[[".panel"]] <- factor("Tree")
132132
# if custom column annotations are provided
133133
if (!is.null(custom_column_labels)) {
134134
# assess the type of input for the custom column annotation
135135
# either a vector or a named vector with positions for specific names
136136
if (is.null(names(custom_column_labels))) {
137-
if (length(custom_column_labels) > nrow(mapping)) {
137+
if (length(custom_column_labels) > nrow(data_axis)) {
138138
warning(paste("Input column label vector has more elements than there are columns.",
139-
"\n", "Using the first ", nrow(mapping)," elements as labels", sep=""))
140-
mapping[["custom_labels"]] <- as.character(custom_column_labels[1:nrow(mapping)])
141-
} else if (length(custom_column_labels) < nrow(mapping)) {
139+
"\n", "Using the first ", nrow(data_axis)," elements as labels", sep=""))
140+
data_axis[["custom_labels"]] <- as.character(custom_column_labels[1:nrow(data_axis)])
141+
} else if (length(custom_column_labels) < nrow(data_axis)) {
142142
warning(paste("Input column label vector has fewer elements than there are columns.",
143143
"\n", "Using all available labels, n = ",
144144
length(custom_column_labels), sep=""))
145-
mapping[["custom_labels"]] <- as.character(c(custom_column_labels,
146-
rep("", nrow(mapping) - length(custom_column_labels))))
145+
data_axis[["custom_labels"]] <- as.character(c(custom_column_labels,
146+
rep("", nrow(data_axis) - length(custom_column_labels))))
147147
} else {
148-
mapping[["custom_labels"]] <- custom_column_labels
148+
data_axis[["custom_labels"]] <- custom_column_labels
149149
}
150150
} else {
151151
if (!is.null(colnames_level)) {
@@ -154,18 +154,18 @@ gheatmap <- function(p, data, offset=0, width=1, low="green", high="red", color=
154154
vector_order <- colnames_level
155155

156156
} else {
157-
vector_order <- as.character(mapping$from)
157+
vector_order <- as.character(data_axis$from)
158158
}
159159
for (elem in custom_column_labels) {
160160
vector_order[which(vector_order == elem)] = names(which(custom_column_labels == elem))
161161
}
162-
mapping[["custom_labels"]] <- vector_order
162+
data_axis[["custom_labels"]] <- vector_order
163163
}
164-
p2 <- p2 + geom_text(data=mapping, aes(x=to, y = y, label=custom_labels),
164+
p2 <- p2 + geom_text(data=data_axis, aes(x=to, y = y, label=custom_labels),
165165
size=font.size, family=family, inherit.aes = FALSE, angle=colnames_angle,
166166
nudge_x=colnames_offset_x, nudge_y = colnames_offset_y, hjust=hjust)
167167
} else {
168-
p2 <- p2 + geom_text(data=mapping, aes(x=to, y = y, label=from), size=font.size, family=family,
168+
p2 <- p2 + geom_text(data=data_axis, aes(x=to, y = y, label=from), size=font.size, family=family,
169169
inherit.aes = FALSE, angle=colnames_angle,
170170
nudge_x=colnames_offset_x, nudge_y = colnames_offset_y, hjust=hjust)
171171
}
@@ -178,7 +178,7 @@ gheatmap <- function(p, data, offset=0, width=1, low="green", high="red", color=
178178
p2 <- p2 + scale_y_continuous(expand = c(0,0))
179179
}
180180

181-
attr(p2, "mapping") <- mapping
181+
attr(p2, "data_axis") <- data_axis
182182
return(p2)
183183
}
184184

0 commit comments

Comments
 (0)