学习vignettes:extending-ggplot2.Rmd的过程中,不明白coords这个数据框里到底有什么?例子中的‘’coords$x, coords$y, coords$shape, coords$colour“感觉都在说明coords里面有x、y、shape、colour变量,那除了这些变量还有什么呢?这个不清楚的话感觉写不来自己的图层,还请高手指点一下!感谢!
文档中的示例代码如下:
library(ggplot2)
library(grid)
GeomSimplePoint <- ggproto("GeomSimplePoint", Geom,
required_aes = c("x", "y"),
default_aes = aes(shape = 19, colour = "black"),
draw_key = draw_key_point,
draw_panel = function(data, panel_params, coord) {
coords <- coord$transform(data, panel_params)
grid::pointsGrob(
coords$x, coords$y,
pch = coords$shape,
gp = grid::gpar(col = coords$colour)
)
}
)
geom_simple_point <- function(mapping = NULL, data = NULL, stat = "identity",
position = "identity", na.rm = FALSE, show.legend = NA,
inherit.aes = TRUE, ...) {
layer(
geom = GeomSimplePoint, mapping = mapping, data = data, stat = stat,
position = position, show.legend = show.legend, inherit.aes = inherit.aes,
params = list(na.rm = na.rm, ...)
)
}
ggplot(mpg, aes(displ, hwy)) +
geom_simple_point()
<sup>Created on 2020-06-14 by the reprex package (v0.3.0)</sup>
文档网址:https://ggplot2.tidyverse.org/articles/extending-ggplot2.html