Skip to content

Instantly share code, notes, and snippets.

@weitinglin
Last active August 22, 2017 17:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save weitinglin/fb2c020033ebbf3a24a2c73500861dbf to your computer and use it in GitHub Desktop.
Save weitinglin/fb2c020033ebbf3a24a2c73500861dbf to your computer and use it in GitHub Desktop.
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