Skip to content

Commit

Permalink
updated docs
Browse files Browse the repository at this point in the history
  • Loading branch information
pvictor committed Sep 5, 2024
1 parent 5c4fbfc commit a7fbbc1
Show file tree
Hide file tree
Showing 6 changed files with 413 additions and 2 deletions.
2 changes: 1 addition & 1 deletion R/layers.R
Original file line number Diff line number Diff line change
Expand Up @@ -1017,7 +1017,7 @@ v_wordcloud <- function(vc,
)
data <- get_data(vc, data)
mapping <- get_mapping(vc, mapping)
mapdata <- eval_mapping(data, rename_aes_lvl(mapping))
mapdata <- eval_mapping_(data, rename_aes_lvl(mapping))
vc$x$type <- c(vc$x$type, "wordcloud")
if (is.null(name) & !is.null(mapping$word))
name <- rlang::as_label(mapping$word)
Expand Down
2 changes: 1 addition & 1 deletion examples/v_pie.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

library(vchartr)

# Bvasic Pie Chart
# Basic Pie Chart
subset(world_electricity, year == 2023 & type == "total") %>%
vchart() %>%
v_pie(aes(x = source, y = generation))
Expand Down
162 changes: 162 additions & 0 deletions inst/examples/app-chart-types.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@

library(shiny)
library(bslib)
library(vchartr)


ui <- page_fluid(
theme = bs_theme(preset = "bootstrap", bg = "#E6E7E7", fg = "#2E2E2E"),

tags$h1("VChart types examples", class = "text-center"),

tags$div(
class = "row row-cols-md-3 g-2 m-auto w-75 mb-5",

lapply(
X = c(
"bar", "line", "area", "area_range", "pie", "hist",
"scatter", "smooth", "boxplot", "jitter", "heatmap",
"treemap", "circlepacking", "sankey", "wordcloud"
),
FUN = function(type) {
tags$div(
class = "col",
tags$div(
class = "card",
vchartOutput(outputId = type, height = "250px")
)
)
}
)

)

)


server <- function(input, output, session) {

output$bar <- renderVchart({
electricity_mix %>%
subset(country %in% c("France", "South Korea")) %>%
vchart() %>%
v_bar(aes(country, generation, fill = source)) %>%
v_scale_color_manual(c(
"oil" = "#80549f",
"coal" = "#a68832",
"solar" = "#d66b0d",
"gas" = "#f20809",
"wind" = "#72cbb7",
"hydro" = "#2672b0",
"nuclear" = "#e4a701"
))
})

output$line <- renderVchart({
vchart(eco2mix) %>%
v_line(aes(date, solar)) %>%
v_specs_datazoom()
})

output$area <- renderVchart({
vchart(eco2mix_long) %>%
v_area(aes(date, production, fill = source), stack = TRUE) %>%
v_scale_y_continuous(min = -2000)
})

output$area_range <- renderVchart({
vchart(temperatures, aes(date)) %>%
v_area(aes(ymin = low, ymax = high))
})

output$pie <- renderVchart({
subset(world_electricity, year == 2023 & type == "total") %>%
vchart() %>%
v_pie(aes(x = source, y = generation))
})

output$hist <- renderVchart({
vchart(palmerpenguins::penguins) %>%
v_hist(
aes(flipper_length_mm),
bar = list(
style = list(
stroke = "white",
line_width = 1,
fill = "forestgreen"
)
)
)
})

output$scatter <- renderVchart({
vchart(palmerpenguins::penguins) %>%
v_scatter(
aes(x = flipper_length_mm, y = body_mass_g, color = species)
)
})

output$smooth <- renderVchart({
vchart(palmerpenguins::penguins) %>%
v_smooth(
aes(x = flipper_length_mm, y = body_mass_g, color = species)
)
})

output$boxplot <- renderVchart({
vchart(palmerpenguins::penguins) %>%
v_boxplot(
aes(x = species, y = body_mass_g)
)
})

output$jitter <- renderVchart({
vchart(palmerpenguins::penguins) %>%
v_jitter(aes(species, bill_length_mm))
})

output$heatmap <- renderVchart({
vchart(co2_emissions) %>%
v_heatmap(aes(x = year, y = country, fill = co2_per_capita))
})

output$treemap <- renderVchart({
vchart(countries_gdp) %>%
v_treemap(
aes(lvl1 = REGION_UN, lvl2 = ADMIN, value = GDP_MD),
label = list(visible = FALSE),
nonLeaf = list(visible = TRUE),
nonLeafLabel = list(visible = TRUE, position = "top")
)
})

output$circlepacking <- renderVchart({
vchart(countries_gdp) %>%
v_circlepacking(
aes(lvl1 = REGION_UN, lvl2 = SUBREGION, lvl3 = ADMIN, value = GDP_MD),
label_visible = FALSE
)
})

output$sankey <- renderVchart({
vchart(energy_sankey) %>%
v_sankey(aes(target, source, value = value))
})

output$wordcloud <- renderVchart({
vchart(top_cran_downloads) %>%
v_wordcloud(
aes(word = package, count = count, color = package),
wordCloudConfig = list(
zoomToFit = list(
shrink = TRUE,
fontSizeLimitMin = 7
)
)
)
})

}


shinyApp(ui = ui, server = server)
217 changes: 217 additions & 0 deletions vignettes/articles/charts.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
---
title: "charts"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{charts}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
```

```{r setup}
library(vchartr)
```


## Bar Chart

Create bar charts with `v_bar()`:

```{r bar}
electricity_mix %>%
subset(country %in% c("France", "South Korea")) %>%
vchart() %>%
v_bar(aes(country, generation, fill = source)) %>%
v_scale_color_manual(c(
"oil" = "#80549f",
"coal" = "#a68832",
"solar" = "#d66b0d",
"gas" = "#f20809",
"wind" = "#72cbb7",
"hydro" = "#2672b0",
"nuclear" = "#e4a701"
))
```



## Line Chart

Create line charts with `v_line()`:

```{r line}
vchart(eco2mix) %>%
v_line(aes(date, solar)) %>%
v_specs_datazoom()
```



## Area Chart

Create area charts with `v_area()`:

```{r area}
vchart(eco2mix_long) %>%
v_area(aes(date, production, fill = source), stack = TRUE) %>%
v_scale_y_continuous(min = -2000)
```


Create area range charts with `v_area()` and providing `ymin` and `ymax` aesthetics:

```{r area_range}
vchart(temperatures, aes(date)) %>%
v_area(aes(ymin = low, ymax = high))
```



## Pie Chart

Create pie or donut charts with `v_pie()`:

```{r pie}
subset(world_electricity, year == 2023 & type == "total") %>%
vchart() %>%
v_pie(aes(x = source, y = generation))
```



## Histogram Chart

Create histograms wioth `v_hist()`:

```{r hist}
vchart(palmerpenguins::penguins) %>%
v_hist(
aes(flipper_length_mm),
bar = list(
style = list(
stroke = "white",
line_width = 1,
fill = "forestgreen"
)
)
)
```



## Scatter Chart

Create scatter charts with `v_scatter()`:

```{r scatter}
vchart(palmerpenguins::penguins) %>%
v_scatter(
aes(x = flipper_length_mm, y = body_mass_g, color = species)
)
```



## Smooth Chart

Create smooth charts with `v_smooth()`:

```{r smooth}
vchart(palmerpenguins::penguins) %>%
v_smooth(
aes(x = flipper_length_mm, y = body_mass_g, color = species)
)
```



## Boxplot

Create boxplots with ``v_boxplot()`:

```{r boxplot}
vchart(palmerpenguins::penguins) %>%
v_boxplot(
aes(x = species, y = body_mass_g)
)
```



## Jittered points

Create jittered points chart with `v_jitter()`:

```{r jitter}
vchart(palmerpenguins::penguins) %>%
v_jitter(aes(species, bill_length_mm))
```



## Heatmap

Create heatmaps with `v_heatmap()`:

```{r heatmap}
vchart(co2_emissions) %>%
v_heatmap(aes(x = year, y = country, fill = co2_per_capita))
```



## Treemap

Create treemaps with `v_treemap()`:

```{r treemap}
vchart(countries_gdp) %>%
v_treemap(
aes(lvl1 = REGION_UN, lvl2 = ADMIN, value = GDP_MD),
label = list(visible = TRUE),
nonLeaf = list(visible = TRUE),
nonLeafLabel = list(visible = TRUE, position = "top")
)
```



## Circlepacking

Create circlepacking charts with `v_circlepacking()`:

```{r circlepacking}
vchart(countries_gdp) %>%
v_circlepacking(
aes(lvl1 = REGION_UN, lvl2 = SUBREGION, lvl3 = ADMIN, value = GDP_MD)
)
```



## Sankey Chart

Create sankey charts with `v_sankey()`:

```{r sankey}
vchart(energy_sankey) %>%
v_sankey(aes(target, source, value = value))
```



## WordCloud

Create wordclouds with `v_wordcloud()`:

```{r wordcloud}
vchart(top_cran_downloads) %>%
v_wordcloud(aes(word = package, count = count, color = package))
```

Binary file added vignettes/figures/vchart-types.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit a7fbbc1

Please sign in to comment.