Toulouse - June, 2016

Online presentation:
http://datastorm-open.github.io/introduction_ramcharts/Toulouse_2016

Introduction

Our motivations:

  • Develop an alternative (free) for smart and interactive visualizations
  • Find a library with richness (able to plot different types of charts)
  • Keep the same logic as R usual functions

From Javascript to R

  • Javascript library amcharts by A. Marcelionis (Lithuanian)
  • Based on hmtlwidgets (compatibility with rmarkdown and shiny)

Note about the package architecture

Usual statistical graphs (am***)


graphicx rAmCharts
boxplot amBoxplot
barplot amBarplot
hist amHist
piechart amPie
plot amPlot, amLines, amTimeSeries
… amRadar, amWind

Boxplot

amBoxplot(Sepal.Length ~ Species, data = iris)

Histogram

amHist(x = iris$Petal.Width, main = "Histogram", freq = FALSE,
       control_hist = list(breaks = 30), xlab = "x-axis")

Bar - column chart

dataset <- get(x = "USArrests", pos = "package:datasets")
##         Murder Assault UrbanPop Rape
## Alabama   13.2     236       58 21.2
## Alaska    10.0     263       48 44.5
amBarplot(y = c("Murder", "Assault", "UrbanPop", "Rape"), legend = TRUE,
          data = head(dataset), stack_type = "regular")

Pie chart

smartphones <- data.frame(label = c("Android", "iOS", "Windows",
                                    "Blackberry OS", "Autres"),
                          value = c(74.3, 20, 5, 0.3, 0.4) * 29.3 / 100)
amPie(smartphones, main = "Part de marché (Kantar/Statista - janvier 2016)")

Time series

data("data_stock_2")
##                  date  ts1  ts2
## 1 2015-01-01 00:00:00 -367   32
## 2 2015-01-01 01:00:00 -370  -47
## 3 2015-01-01 02:00:00 -396 -135
amTimeSeries(data_stock_2, "date", c("ts1", "ts2"))

Non statistical usual graphs (am***)




Finance Marketing
amOHLC amFloatingBar
amStockChart amFunnel
amWaterfall amGauge

Waterfall chart

##          label value operation
## 1 Capital 2014 50000     total
## 2        Wages 30000     minus
## 3  Investments  5000     minus
amWaterfall(data = dataset, creditsPosition = "top-right") %>% 
  setCategoryAxis(labelRotation = 30)

OHLC chart (open-high-low-close)

data("data_candleStick2")
##     category   open close    low   high
## 1 2015-01-01 136.65 136.4 134.15 136.96
## 2 2015-01-02 135.26 131.8 131.50 135.95
amOHLC(data = data_candleStick2, dataDateFormat = "YYYY-MM-DD")

Floating bar chart

data("data_fbar")
##   country visits_inf visits_sup   color
## 1     USA       3000       3025 #FF0F00
## 2   China       1800       1882 #FF6600
amFloatingBar(x = "country", y_inf = "visits_inf", y_sup = "visits_sup",
              export = TRUE, data = data_fbar, labelRotation = 45)

Customize chart from scratch

Assume that we just want to plot a curve with the following features: title, subtitle, named axis, cursor with custom tooltips

amSerialChart(dataProvider = uspop_df, categoryField = "Year") %>%
  addGraph(valueField = "US_Population", lineColor = "brown",
           balloonText = "[[value]] millions citizens") %>%
  addTitle(text = "Evolution of the US population") %>%
  addTitle(text = "from 1790 to 1970 by decade", size = 8) %>%
  addValueAxis(title = "Population (in millions)") %>%
  setChartCursor()

(Custom) Bar chart

my_points <- rnorm(n = 6, mean = 300, sd = 50) %>% round(2)
amBarplot(y = c("Murder", "Assault", "UrbanPop", "Rape"), data = head(dataset),
          stack_type = "regular", theme = "light") %>%
  setCategoryAxis(gridAlpha = 0) %>% # remove vertical grid
  setValueAxes(list()) %>% # remove content of attribute 'valueAxes'
  # to set a new one without grid
  addValueAxis(stackType = "regular", gridAlpha = 0, position = "right") %>%
  amLines(y = my_points, type = "sl") %>%
  setLegend(enabled = TRUE)

Conclusion


  • A new package 'all-in-one' to generate JavaScript charts

  • Easy to use with R associated features (shiny, markdown)

  • Great flexibility, infinite customization

  • Implements almost all functions of the amcharts library

  • Available on CRAN and Github (frequent updates)

  • Simplicity of am*** functions

Links