-
-
Save weitinglin/fb2c020033ebbf3a24a2c73500861dbf to your computer and use it in GitHub Desktop.
Create ggproto object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Construct new_Geom class inheired from Geom class | |
new_Geom <- ggproto("new_Geom", Geom, | |
required_aes = c("x", "y"), | |
defaut_aes = aes(fill="yello"), | |
draw_key_key = draw_key_polygon, | |
draw_group = function(data, panel_scales, coord){ | |
coords <- coord$transform(data, panel_scales) | |
grid::polygonGrob( | |
x = coords_df$x, | |
y = coords_df$y, | |
gp = grid::gpar(col = coords_df$colour, | |
fill = coords_df$fill, | |
alpha = coords_df$alpha) | |
) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# create ggproto object | |
# 會發現語法承襲自proto的系統,不需要像是RC system的field等 | |
new_ggproto_object <- ggproto("Class_name", | |
parent_ggproto_class, | |
x = 0 | |
f1_method = function(self,n){ | |
self$x <- self$x + n | |
self$x | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment