Universal ggplot block with selectable visualization types
Source:R/ggplot-block.R
new_ggplot_block.RdA flexible block that allows users to select from various ggplot2 geoms and dynamically shows relevant aesthetics for the selected visualization.
Arguments
- type
Initial chart type (default "point"). Options: "point", "bar", "line", "boxplot", "violin", "density", "area", "histogram", "pie"
- x
Column for x-axis
- y
Column for y-axis
- color
Column for color aesthetic
- fill
Column for fill aesthetic
- size
Column for size aesthetic
- shape
Column for shape aesthetic
- linetype
Column for linetype aesthetic
- group
Column for group aesthetic
- alpha
Column for alpha aesthetic (variable transparency)
- density_alpha
Fixed alpha value for density plots (default 0.8)
- position
Position adjustment for certain geoms
- bins
Number of bins for histogram
- donut
Whether to create donut chart when type is "pie" (default FALSE)
- ...
Forwarded to
new_plot_block
Examples
# Create a scatter plot block
new_ggplot_block(type = "point", x = "mpg", y = "hp")
#> <ggplot_block<ggplot_transform_block<block>>>
#> Name: "Ggplot"
#> Data inputs: "data"
#> Initial block state:
#> $ type : chr "point"
#> $ x : chr "mpg"
#> $ y : chr "hp"
#> $ color : chr(0)
#> $ fill : chr(0)
#> $ size : chr(0)
#> $ shape : chr(0)
#> $ linetype : chr(0)
#> $ group : chr(0)
#> $ alpha : chr(0)
#> $ density_alpha: num 0.8
#> $ position : chr "stack"
#> $ bins : num 30
#> $ donut : logi FALSE
#> Constructor: blockr.ggplot::new_ggplot_block()
# Create a bar chart block
new_ggplot_block(type = "bar", x = "cyl")
#> <ggplot_block<ggplot_transform_block<block>>>
#> Name: "Ggplot"
#> Data inputs: "data"
#> Initial block state:
#> $ type : chr "bar"
#> $ x : chr "cyl"
#> $ y : chr(0)
#> $ color : chr(0)
#> $ fill : chr(0)
#> $ size : chr(0)
#> $ shape : chr(0)
#> $ linetype : chr(0)
#> $ group : chr(0)
#> $ alpha : chr(0)
#> $ density_alpha: num 0.8
#> $ position : chr "stack"
#> $ bins : num 30
#> $ donut : logi FALSE
#> Constructor: blockr.ggplot::new_ggplot_block()
if (interactive()) {
library(blockr.core)
serve(new_ggplot_block(), list(data = mtcars))
}