Skip to content

Instantly share code, notes, and snippets.

@weitinglin

weitinglin/Geom

Last active Aug 22, 2017
Embed
What would you like to do?
Create ggproto object
# 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)
)
}
# 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