This document demonstrates how to implement and plot different chart types and chart combinations using minCombinR. It will be using the classic tabular diamonds dataset that is built into R. This document assumes that you have already run the "Getting started with minCombinR".
devtools::load_all() # TODO: temporary once things are done library(dplyr) library(shiny) library(ggplot2) # Load in the mtcars dataset data(diamonds) # Here is what the diamonds dataset looks like (first 6 rows): head(diamonds) diamonds<-as.data.frame(diamonds)
# Let's specify and plot some single charts. # Bar chart: bar_chart <- specify_single(chart_type = "bar", data = "diamonds", x = "cut") plot(bar_chart) # Line chart: diamonds_GT_10000 <- diamonds %>% filter(price > 10000) line_chart <- specify_single(chart_type = "line", data = "diamonds_GT_10000", x = "carat", y = "price") plot(line_chart) # Scatter plot: scatter_chart <- specify_single(chart_type = "scatter", data = "diamonds", x = "carat", y = "price") plot(scatter_chart) # Histogram: histogram_chart <- specify_single(chart_type = "histogram", data = "diamonds", x = "carat") plot(histogram_chart) # Probability Density Function (PDF) plot: pdf_chart <- specify_single(chart_type = "pdf", data = "diamonds", x = "carat") plot(pdf_chart) # Boxplot: boxplot_chart <- specify_single(chart_type = "boxplot", data = "diamonds", x = "color", y = "price") plot(boxplot_chart) # Swarm plot: swarmplot_chart <- specify_single(chart_type = "swarmplot", data = "diamonds", x = "color", y = "price") plot(swarmplot_chart) # We'll even let you make a pie chart: pie_chart <- specify_single(chart_type = "pie", data = "diamonds", x = "cut") plot(pie_chart)
Unaligned combination can be used when you just want to put a bunch of plots together and there are no spatial or visual linkages between the plots themselves.
# Specify that you want to combine the bar_chart, box plot, scatter_chart and swarmplot_chart mg_combo <- specify_combination(combo_type = "unaligned", base_charts = c("bar_chart", "line_chart", "scatter_chart")) # Now plot it! plot(mg_combo)
Small multiple charts are visually linked because they show the same underlying chart type while showing different subsets of the data. Another common name for this is facets.
# Scatter plot: scatter_chart_tp <- specify_single(chart_type = "boxplot", data = "diamonds", x = "clarity", y = "price") # Now specify the small multiple combination sm_combo_scatter <- specify_combination(combo_type = "small_multiple", base_charts = "scatter_chart_tp", facet_by = "cut") plot(sm_combo_scatter)
It could be interesting to align several different chart types together by color.
If you have nontabular data, minCombinR will find matching links between non-tabular and tabular data so they can be color aligned. Mtcars is a tabular dataset, so we won't be demonstrating this here but if you are interested, check out the examples using the ebola dataset that can be found in the inst/examples folder in the r markdown notebook called chart_combinations.
# Specify that you want to combine with color color_combo <- specify_combination(combo_type = "color_aligned", base_charts = c("scatter_chart", "bar_chart"), link_by = "clarity") # Now plot! plot(color_combo)
# Scatter plot: scatter_chart1 <- specify_single(chart_type = "scatter", data = "diamonds", x = "carat", y = "price") plot(scatter_chart) # Scatter plot: scatter_chart2 <- specify_single(chart_type = "scatter", data = "diamonds", x = "carat", y = "price") plot(scatter_chart) # Scatter plot: scatter_chart3 <- specify_single(chart_type = "scatter", data = "diamonds", x = "carat", y = "price") plot(scatter_chart) composite_combo <- specify_combination("spatial_aligned", c("scatter_chart1", "scatter_chart2", "scatter_chart3")) plot(composite_combo)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.