## ----include = FALSE---------------------------------------------------------- knitr::opts_chunk$set( collapse = TRUE, comment = "#>", eval = FALSE ) ## ----voronoi_esm-------------------------------------------------------------- # library(rMosaic) # # # Generate synthetic penguins dataset # set.seed(42) # penguins_df <- data.frame( # bill_length = rnorm(150, mean = 40, sd = 5), # bill_depth = rnorm(150, mean = 18, sd = 3), # species = sample(c("Adelie", "Gentoo", "Chinstrap"), 150, replace = TRUE) # ) # # # Define ESM spec as raw JavaScript text # voronoi_esm <- " # const $mesh = Param.value(0); # const $hull = Param.value(0); # # export default vconcat( # plot( # voronoi( # from('penguins'), # { x: 'bill_length', y: 'bill_depth', # stroke: 'white', strokeWidth: 1, # strokeOpacity: 0.2, fill: 'species', fillOpacity: 0.2 } # ), # hull( # from('penguins'), # { x: 'bill_length', y: 'bill_depth', # stroke: 'species', strokeOpacity: $hull, strokeWidth: 1.5 } # ), # delaunayMesh( # from('penguins'), # { x: 'bill_length', y: 'bill_depth', z: 'species', # stroke: 'species', strokeOpacity: $mesh, strokeWidth: 1 } # ), # dot( # from('penguins'), # { x: 'bill_length', y: 'bill_depth', # fill: 'species', r: 2 } # ), # frame(), # width(680), # height(480) # ), # hconcat( # menu({ # label: 'Delaunay Mesh', # options: [ # { value: 0, label: 'Hide' }, # { value: 0.5, label: 'Show' } # ], # as: $mesh # }), # hspace(5), # menu({ # label: 'Convex Hull', # options: [ # { value: 0, label: 'Hide' }, # { value: 1, label: 'Show' } # ], # as: $hull # }) # ) # ); # " # # # Run the application with ESM spec # runMosaicApp( # spec = voronoi_esm, # specType = "esm", # data = list(penguins = penguins_df), # title = "Voronoi Diagram (ESM)" # )