Skip to content

Commit

Permalink
added more examples
Browse files Browse the repository at this point in the history
  • Loading branch information
pvictor committed Sep 23, 2024
1 parent e041f0f commit 2b88636
Show file tree
Hide file tree
Showing 8 changed files with 185 additions and 3 deletions.
2 changes: 1 addition & 1 deletion R/scales.R
Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,7 @@ v_scale_gradient <- function(vc,
#' @return A [vchart()] `htmlwidget` object.
#' @export
#'
# @examples
#' @example examples/scale_size.R
v_scale_size <- function(vc,
name = NULL,
range = c(5, 30),
Expand Down
6 changes: 4 additions & 2 deletions R/specs.R
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,8 @@ v_specs_custom_mark <- function(vc, ...) {
#'
#' @return A [vchart()] `htmlwidget` object.
#' @export
#'
#'
#' @example examples/crosshair.R
v_specs_crosshair <- function(vc, ...) {
vc <- .vchart_specs2(
vc,
Expand All @@ -431,7 +432,8 @@ v_specs_crosshair <- function(vc, ...) {
#'
#' @return A [vchart()] `htmlwidget` object.
#' @export
#'
#'
#' @example examples/indicator.R
v_specs_indicator <- function(vc, ...) {
vc <- .vchart_specs2(
vc,
Expand Down
34 changes: 34 additions & 0 deletions examples/crosshair.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

library(vchartr)

data.frame(month = month.abb, value = sample(1:50, 12)) %>%
vchart() %>%
v_line(aes(month, value)) %>%
v_specs_crosshair(
xField = list(
visible = TRUE,
line = list(type = "rect"),
defaultSelect = list(
axisIndex = 0,
datum = "May"
),
label = list(visible = TRUE)
),
yField = list(
visible = TRUE,
defaultSelect = list(
axisIndex = 1,
datum = 30
),
line = list(
style = list(
lineWidth = 1,
opacity = 1,
stroke = "#000",
lineDash = c(2, 2)
)
),
label = list(visible = TRUE)
)
)

40 changes: 40 additions & 0 deletions examples/indicator.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

library(vchartr)

electricity_mix %>%
subset(country == "France") %>%
vchart() %>%
v_pie(
aes(x = source, y = generation),
outerRadius = 0.8,
innerRadius = 0.5,
padAngle = 0.6
) %>%
v_specs_tooltip(visible = FALSE) %>%
v_specs_indicator(
visible = TRUE,
trigger = "hover",
limitRatio = 0.5,
title = list(
visible = TRUE,
autoFit = TRUE,
fitStrategy = "inscribed",
style = list(
fontWeight = "bolder",
fill = "#888",
text = JS("datum => datum !== null ? datum.x : ''")
)
),
content = list(
list(
visible = TRUE,
autoFit = TRUE,
fitStrategy = "inscribed",
style = list(
fontWeight = "bolder",
fill = "#000",
text = JS("datum => datum !== null ? Math.round(datum.y) + 'TWh' : ''")
)
)
)
)
13 changes: 13 additions & 0 deletions examples/scale_size.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
library(vchartr)
data("penguins", package = "palmerpenguins")

vchart(penguins) %>%
v_scatter(aes(
x = bill_length_mm,
y = bill_depth_mm,
size = body_mass_g
)) %>%
v_scale_size(
name = "Body mass",
range = c(1, 20)
)
15 changes: 15 additions & 0 deletions man/v_scale_size.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions man/v_specs_crosshair.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 42 additions & 0 deletions man/v_specs_indicator.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2b88636

Please sign in to comment.