我想看看因子值在哪里变成数字值。我试图通过简单地print
在任何地方添加语句来实现这一点......
geom_tile2 <- function(mapping = NULL, data = NULL,
stat = "identity2", position = "identity",
...,
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE) {
layer(
data = data,
mapping = mapping,
stat = stat,
geom = GeomTile2,
position = position,
show.legend = show.legend,
inherit.aes = inherit.aes,
params = list(
na.rm = na.rm,
...
)
)
}
GeomTile2 <- ggproto("GeomTile2", GeomRect,
extra_params = c("na.rm", "width", "height"),
setup_data = function(data, params) {
print(data)
data$width <- data$width %||% params$width %||% resolution(data$x, FALSE)
data$height <- data$height %||% params$height %||% resolution(data$y, FALSE)
transform(data,
xmin = x - width / 2, xmax = x + width / 2, width = NULL,
ymin = y - height / 2, ymax = y + height / 2, height = NULL
)
},
default_aes = aes(fill = "grey20", colour = NA, size = 0.1, linetype = 1,
alpha = NA),
required_aes = c("x", "y"),
draw_key = draw_key_polygon
)
和
stat_identity2 <- function(mapping = NULL, data = NULL,
geom = "point", position = "identity",
...,
show.legend = NA,
inherit.aes = TRUE) {
layer(
data = data,
mapping = mapping,
stat = StatIdentity2,
geom = geom,
position = position,
show.legend = show.legend,
inherit.aes = inherit.aes,
params = list(
na.rm = FALSE,
...
)
)
}
StatIdentity2 <- ggproto("StatIdentity2", Stat,
setup_data = function(data, params) {
print(data)
data
},
compute_layer = function(data, scales, params) {
print(data)
print("stat end")
data
}
)
但是当我跑步时
ggplot(data.frame(x = rep(c("y", "n"), 6), y = rep(c("y", "n"), each = 6)),
aes(x = x, y = y)) +
geom_tile2()
x
和y
是setup_data
函数中的数字stat
。查看包的 Github 存储库,我似乎无法找到这种转换为坐标的实际发生位置?