static_drawr_examples.Rmd
library(shinysense)
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
You can embedd you-draw-it style charts in your rmarkdown reports or plain standalone HTML documents by using shinysense::drawr
. The options work almost identical to how they do in shinydrawr
.
To demo this let’s generate a simple timeseries dataset for our charts:
plot_data <- tibble(
x = 1:50,
value = sin(x)
)
plot_data
#> # A tibble: 50 x 2
#> x value
#> <int> <dbl>
#> 1 1 0.841
#> 2 2 0.909
#> 3 3 0.141
#> 4 4 -0.757
#> 5 5 -0.959
#> 6 6 -0.279
#> 7 7 0.657
#> 8 8 0.989
#> 9 9 0.412
#> 10 10 -0.544
#> # … with 40 more rows
Now we can get into building our plots. We can start with the defaults.
# Standard mode
drawr(
plot_data,
x_col = x,
y_col = value,
draw_start = 25 # Start obscuring data after x = 25
)
You can do things like change the colors of the lines:
drawr(
plot_data,
x_col = x,
y_col = value,
draw_start = 25,
data_line_color = 'red',
drawn_line_color = 'green'
)
You can customize the axes ranges:
drawr(
plot_data,
x_col = x,
y_col = value,
draw_start = 25,
x_range = c(-5, 55),
y_range = c(-5, 5)
)
You can give your plot a title and custom axis labels.
drawr(
plot_data,
x_col = x,
x_lab = 'time',
y_col = value,
y_lab = 'dollars',
title = 'Guess the pattern!',
draw_start = 35
)
You can even just have the user draw for fun. (Makes more sense when used with shinydrawr
where data can be retreived)
For more information on all the options available visit the shinysense website’s documentation or simply run ?drawr
in your R console.