knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
library(vchartr)
Create bar charts with v_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" ))
Create line charts with v_line()
:
vchart(eco2mix) %>% v_line(aes(date, solar)) %>% v_specs_datazoom()
Create area charts with v_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:
vchart(temperatures, aes(date)) %>% v_area(aes(ymin = low, ymax = high))
Create pie or donut charts with v_pie()
:
subset(world_electricity, year == 2023 & type == "total") %>% vchart() %>% v_pie(aes(x = source, y = generation))
Create histograms with v_hist()
:
vchart(palmerpenguins::penguins) %>% v_hist( aes(flipper_length_mm), bar = list( style = list( stroke = "white", line_width = 1, fill = "forestgreen" ) ) )
Create scatter charts with v_scatter()
:
vchart(palmerpenguins::penguins) %>% v_scatter( aes(x = flipper_length_mm, y = body_mass_g, color = species) )
Create smooth charts with v_smooth()
:
vchart(palmerpenguins::penguins) %>% v_smooth( aes(x = flipper_length_mm, y = body_mass_g, color = species) )
Create boxplots with `v_boxplot()
:
vchart(palmerpenguins::penguins) %>% v_boxplot( aes(x = species, y = body_mass_g) )
Create jittered points chart with v_jitter()
:
vchart(palmerpenguins::penguins) %>% v_jitter(aes(species, bill_length_mm))
Create heatmaps with v_heatmap()
:
vchart(co2_emissions) %>% v_heatmap(aes(x = year, y = country, fill = co2_per_capita))
Create treemaps with v_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") )
Create circlepacking charts with v_circlepacking()
:
vchart(countries_gdp) %>% v_circlepacking( aes(lvl1 = REGION_UN, lvl2 = SUBREGION, lvl3 = ADMIN, value = GDP_MD) )
Create sankey charts with v_sankey()
:
vchart(energy_sankey) %>% v_sankey(aes(target, source, value = value))
Create wordclouds with v_wordcloud()
:
vchart(top_cran_downloads) %>% v_wordcloud(aes(word = package, count = count, color = package))
Create venn diagrams with v_venn
:
data.frame( sets = c("A", "B", "C", "A,B", "A,C", "B,C", "A,B,C"), value = c(8, 10, 12, 4, 4, 4, 2) ) %>% vchart() %>% v_venn(aes(sets = sets, value = value))
Create waterfall charts with v_waterfall
:
data.frame( desc = c("Starting Cash", "Sales", "Refunds", "Payouts", "Court Losses", "Court Wins", "Contracts", "End Cash"), amount = c(2000, 3400, -1100, -100, -6600, 3800, 1400, 2800) ) %>% vchart() %>% v_waterfall(aes(x = desc, y = amount))
Create sunburst charts with v_sunburst
:
vchart(countries_gdp) %>% v_sunburst( aes(lvl1 = REGION_UN, lvl2 = SUBREGION, lvl3 = ADMIN, value = GDP_MD), gap = 10, labelAutoVisible = list( enable = TRUE ), labelLayout = list( align = "center", rotate = "radial" ) )
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.