From c0e283614e3db643114bb50801956182848f76e3 Mon Sep 17 00:00:00 2001 From: Kohske Takahashi at Haruna Date: Tue, 25 Feb 2014 11:26:27 +0900 Subject: [PATCH] Import examples into demo so users can run them. --- demo/00Index | 9 + demo/datatables.R | 36 ++ demo/dimple.R | 969 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ demo/highcharts.R | 102 ++++++ demo/leaflet.R | 206 ++++++++++++ demo/morris.R | 43 +++ demo/nvd3.R | 196 +++++++++++ demo/polycharts.R | 53 +++ demo/rickshaw.R | 91 +++++ demo/xcharts.R | 30 ++ 10 files changed, 1735 insertions(+) create mode 100644 demo/00Index create mode 100644 demo/datatables.R create mode 100644 demo/dimple.R create mode 100644 demo/highcharts.R create mode 100644 demo/leaflet.R create mode 100644 demo/morris.R create mode 100644 demo/nvd3.R create mode 100644 demo/polycharts.R create mode 100644 demo/rickshaw.R create mode 100644 demo/xcharts.R diff --git a/demo/00Index b/demo/00Index new file mode 100644 index 0000000..9194d09 --- /dev/null +++ b/demo/00Index @@ -0,0 +1,9 @@ +datatables +dimple +highcharts +leaflet +morris +nvd3 +polycharts +rickshaw +xcharts diff --git a/demo/datatables.R b/demo/datatables.R new file mode 100644 index 0000000..8a639dd --- /dev/null +++ b/demo/datatables.R @@ -0,0 +1,36 @@ +..p. <- function() invisible(readline("\nPress to continue: ")) +library(rCharts) + +dt <- dTable( + iris, + sPaginationType= "full_numbers" +) +dt + +..p.() # ================================ + +dt <- dTable( + iris, + bScrollInfinite = T, + bScrollCollapse = T, + sScrollY = "200px", + width = "500px" +) +dt + +..p.() # ================================ + +data(Orange) +dt <- dTable( + Orange, + sScrollY = "200px", + bScrollCollapse = T, + bPaginate = F, + bJQueryUI = T, + aoColumnDefs = list( + sWidth = "5%", aTargets = list(-1) + ) +) +dt + +..p.() # ================================ diff --git a/demo/dimple.R b/demo/dimple.R new file mode 100644 index 0000000..83ba61e --- /dev/null +++ b/demo/dimple.R @@ -0,0 +1,969 @@ +..p. <- function() invisible(readline("\nPress to continue: ")) +library(rCharts) + +#get data used by dimple for all of its examples as a first test +data <- read.delim( + "http://pmsi-alignalytics.github.io/dimple/data/example_data.tsv" +) + +# original data is ~ 1000 rows, which is too huge as demo. +set.seed(42) +data <- data[sample(nrow(data), 50), ] + +#eliminate . to avoid confusion in javascript +colnames(data) <- gsub("[.]","",colnames(data)) + +## example 1 vt bar +d1 <- dPlot( + x ="Month" , + y = "UnitSales", + data = data, + type = "bar" +) +d1$xAxis(orderRule = "Date") +d1 + +..p.() # ================================ + +## example 2 vt stacked bar +d1 <- dPlot( + x ="Month" , + y = "UnitSales", + groups = "Channel", + data = data, + type = "bar" +) +d1$xAxis(orderRule = "Date") +d1$legend( + x = 60, + y = 10, + width = 700, + height = 20, + horizontalAlign = "right" +) +d1 + +..p.() # ================================ + +## example 3 vertical 100% bar +#use from above and just change y axis type +d1$yAxis(type = "addPctAxis") +d1 + +..p.() # ================================ + +## example 4 vertical grouped bar +d1 <- dPlot( + x = c("PriceTier","Channel"), + y = "UnitSales", + groups = "Channel", + data = data, + type = "bar" +) +d1$legend( + x = 60, + y = 10, + width = 700, + height = 20, + horizontalAlign = "right" +) +d1 + +..p.() # ================================ + +## example 5 vertical stack grouped bar +d1 <- dPlot( + x = c("PriceTier","Channel"), + y = "UnitSales", + groups = "Owner", + data = data, + type = "bar" +) +d1$legend( + x = 200, + y = 10, + width = 400, + height = 20, + horizontalAlign = "right" +) +d1 + + +..p.() # ================================ + +## example 6 vertical 100% Grouped Bar +#just change y Axis +d1$yAxis(type = "addPctAxis") +d1 + +..p.() # ================================ + +## example 7 horizontal bar +d1 <- dPlot( + Month ~ UnitSales, + data = data, + type = "bar" +) +d1$xAxis(type = "addMeasureAxis") +#good test of orderRule on y instead of x +d1$yAxis(type = "addCategoryAxis", orderRule = "Date") +d1 + + +..p.() # ================================ + +## example 8 horizontal stacked bar +d1 <- dPlot( + Month ~ UnitSales, + groups = "Channel", + data = data, + type = "bar" +) +d1$xAxis(type = "addMeasureAxis") +#good test of orderRule on y instead of x +d1$yAxis(type = "addCategoryAxis", orderRule = "Date") +d1$legend( + x = 200, + y = 10, + width = 400, + height = 20, + horizontalAlign = "right" +) +d1 + +..p.() # ================================ + +## example 9 horizontal 100% bar +d1$xAxis(type = "addPctAxis") +d1 + + +..p.() # ================================ + +## example 10 horizontal stacked bar +d1 <- dPlot( + x = "UnitSales", + y = c("PriceTier","Channel"), + groups = "Channel", + data = data, + type = "bar" +) +d1$xAxis(type = "addMeasureAxis") +#good test of orderRule on y instead of x +d1$yAxis(type = "addCategoryAxis") +d1$legend( + x = 200, + y = 10, + width = 400, + height = 20, + horizontalAlign = "right" +) +d1 + + +..p.() # ================================ + +## example 11 horizontal stacked grouped bar +d1 <- dPlot( + x = "UnitSales", + y = c("PriceTier","Channel"), + groups = "Owner", + data = data, + type = "bar" +) +d1$xAxis(type = "addMeasureAxis") +#good test of orderRule on y instead of x +d1$yAxis(type = "addCategoryAxis") +d1$legend( + x = 200, + y = 10, + width = 400, + height = 20, + horizontalAlign = "right" +) +d1 + +..p.() # ================================ + +## example 12 horizontal 100% grouped bar +d1$xAxis(type = "addPctAxis") +d1 + + +..p.() # ================================ + +## example 13 vertical marimekko +d1 <- dPlot( + UnitSales ~ Channel, + groups = "Owner", + data = data, + type = "bar" +) +d1$xAxis(type = "addAxis", measure = "UnitSales", showPercent = TRUE) +d1$yAxis(type = "addPctAxis") +d1$legend( + x = 200, + y = 10, + width = 400, + height = 20, + horizontalAlign = "right" +) +d1 +#test with storyboard +d1$set(storyboard = "Date") +d1 + +..p.() # ================================ + +## example 14 horizontal marimekko +d1 <- dPlot( + Channel ~ UnitSales, + groups = "Owner", + data = data, + type = "bar" +) +d1$yAxis(type = "addAxis", measure = "UnitSales", showPercent = TRUE) +d1$xAxis(type = "addPctAxis") +d1$legend( + x = 200, + y = 10, + width = 400, + height = 20, + horizontalAlign = "right" +) +d1 + + +..p.() # ================================ + +## example 15 block matrix +d1 <- dPlot( + x = c("Channel","PriceTier"), + y = "Owner", + groups = "PriceTier", + data = data, + type = "bar" +) +d1$yAxis(type = "addCategoryAxis") +d1$xAxis(type = "addCategoryAxis") +d1$legend( + x = 200, + y = 10, + width = 400, + height = 20, + horizontalAlign = "right" +) +d1 + + +..p.() # ================================ + +## example 16 Scatter +d1 <- dPlot( + OperatingProfit~UnitSales, + groups = c("SKU","Channel"), + data = subset(data, Date == "01/12/2012"), + type = "bubble" +) +d1$xAxis( type = "addMeasureAxis" ) +d1$yAxis( type = "addMeasureAxis" ) +d1$legend( + x = 200, + y = 10, + width = 500, + height = 20, + horizontalAlign = "right" +) +d1 + + +..p.() # ================================ + +## example 17 Vertical Lollipop +d1 <- dPlot( + UnitSales ~ Month, + groups = "Channel", + data = data, + type = "bubble" +) +#defaults to yAxis (Measure) and xAxis (Category) +d1$xAxis( orderRule = "Date") +d1$legend( + x = 200, + y = 10, + width = 500, + height = 20, + horizontalAlign = "right" +) +d1 + + +..p.() # ================================ + +## example 18 Vertical Grouped Lollipop +d1 <- dPlot( + y = "UnitSales", + x = c("PriceTier","Channel"), + groups = "Channel", + data = data, + type = "bubble" +) +#defaults to yAxis (Measure) and xAxis (Category) +d1$legend( + x = 200, + y = 10, + width = 500, + height = 20, + horizontalAlign = "right" +) +d1 + + +..p.() # ================================ + +## example 19 Horizontal Lollipop +d1 <- dPlot( + x = "UnitSales", + y = "Month", + groups = "Channel", + data = data, + type = "bubble" +) +d1$xAxis( type = "addMeasureAxis" ) +d1$yAxis( type = "addCategoryAxis", orderRule = "Date") +d1$legend( + x = 200, + y = 10, + width = 500, + height = 20, + horizontalAlign = "right" +) +d1 + + +..p.() # ================================ + +## example 20 Horizontal Grouped Lollipop +d1 <- dPlot( + x = "UnitSales", + y = c("PriceTier","Channel"), + groups = "Channel", + data = data, + type = "bubble" +) +d1$xAxis( type = "addMeasureAxis" ) +d1$yAxis( type = "addCategoryAxis") +d1$legend( + x = 200, + y = 10, + width = 500, + height = 20, + horizontalAlign = "right" +) +d1 + + + +..p.() # ================================ + +## example 21 Dot Matrix +d1 <- dPlot( + y = "Owner", + x = c("Channel","PriceTier"), + groups = "PriceTier", + data = data, + type = "bubble" +) +d1$xAxis( type = "addCategoryAxis" ) +d1$yAxis( type = "addCategoryAxis") +d1$legend( + x = 200, + y = 10, + width = 500, + height = 20, + horizontalAlign = "right" +) +d1 + + +..p.() # ================================ + +## example 22 Bubble +d1 <- dPlot( + x = "UnitSalesMonthlyChange", + y = "PriceMonthlyChange", + z = "OperatingProfit", + groups = c("SKU","Channel"), + data = subset(data, Date == "01/12/2012"), + type = "bubble" +) +d1$xAxis( type = "addMeasureAxis" ) +d1$yAxis( type = "addMeasureAxis" ) +d1$zAxis( type = "addMeasureAxis" ) +d1$legend( + x = 200, + y = 10, + width = 500, + height = 20, + horizontalAlign = "right" +) +d1 + + +..p.() # ================================ + +## example 23 Vertical Bubble Lollipop +d1 <- dPlot( + x = "Month", + y = "UnitSales", + z = "OperatingProfit", + groups = "Channel", + data = subset( + data, + Date %in% c( + "01/07/2012", + "01/08/2012", + "01/09/2012", + "01/10/2012", + "01/11/2012", + "01/12/2012" + ) + ), + type = "bubble" +) +d1$xAxis( type = "addCategoryAxis", orderRule = "Date" ) +d1$yAxis( type = "addMeasureAxis" ) +d1$zAxis( type = "addMeasureAxis" ) +d1$legend( + x = 200, + y = 10, + width = 500, + height = 20, + horizontalAlign = "right" +) +d1 + + +#..p.() # ================================ + +## example 24 Vertical Grouped Bubble Lollipop +d1 <- dPlot( + x = c("PriceTier","Channel"), + y = "UnitSales", + z = "OperatingProfit", + groups = "Channel", + data = subset( + data, + Date %in% c( + "01/07/2012", + "01/08/2012", + "01/09/2012", + "01/10/2012", + "01/11/2012", + "01/12/2012" + ) + ), + type = "bubble" +) +d1$xAxis( type = "addCategoryAxis" ) +d1$yAxis( type = "addMeasureAxis" ) +d1$zAxis( type = "addMeasureAxis" ) +d1$legend( + x = 200, + y = 10, + width = 500, + height = 20, + horizontalAlign = "right" +) +d1 + + +..p.() # ================================ + +## example 25 Horizontal Bubble Lollipop +d1 <- dPlot( + y = "Month", + x = "UnitSales", + z = "OperatingProfit", + groups = "Channel", + data = subset( + data, + Date %in% c( + "01/07/2012", + "01/08/2012", + "01/09/2012", + "01/10/2012", + "01/11/2012", + "01/12/2012" + ) + ), + type = "bubble" +) +d1$yAxis( type = "addCategoryAxis", orderRule = "Date" ) +d1$xAxis( type = "addMeasureAxis" ) +d1$zAxis( type = "addMeasureAxis" ) +d1$legend( + x = 200, + y = 10, + width = 500, + height = 20, + horizontalAlign = "right" +) +d1 + + +#..p.() # ================================ + +## example 26 Horizontal Grouped Bubble Lollipop +d1 <- dPlot( + y = c("PriceTier","Channel"), + x = "UnitSales", + z = "OperatingProfit", + groups = "Channel", + data = subset( + data, + Date %in% c( + "01/07/2012", + "01/08/2012", + "01/09/2012", + "01/10/2012", + "01/11/2012", + "01/12/2012" + ) + ), + type = "bubble" +) +d1$yAxis( type = "addCategoryAxis" ) +d1$xAxis( type = "addMeasureAxis" ) +d1$zAxis( type = "addMeasureAxis" ) +d1$legend( + x = 200, + y = 10, + width = 500, + height = 20, + horizontalAlign = "right" +) +d1 + + +..p.() # ================================ + +## example 27 Bubble Matrix +d1 <- dPlot( + x = c( "Channel", "PriceTier"), + y = "Owner", + z = "Distribution", + groups = "PriceTier", + data = data, + type = "bubble", + aggregate = "dimple.aggregateMethod.max" +) +d1$xAxis( type = "addCategoryAxis" ) +d1$yAxis( type = "addCategoryAxis" ) +d1$zAxis( type = "addMeasureAxis", overrideMax = 200 ) +d1$legend( + x = 200, + y = 10, + width = 500, + height = 20, + horizontalAlign = "right" +) +d1 + + +..p.() # ================================ + +## example 28 Area +d1 <- dPlot( + UnitSales ~ Month, + data = subset(data, Owner %in% c("Aperture","Black Mesa")), + type = "area" +) +d1$xAxis(type = "addCategoryAxis", orderRule = "Date") +d1$yAxis(type = "addMeasureAxis") +d1 + + +..p.() # ================================ + +## example 29 Stacked Area +d1 <- dPlot( + UnitSales ~ Month, + groups = "Channel", + data = subset(data, Owner %in% c("Aperture","Black Mesa")), + type = "area" +) +d1$xAxis(type = "addCategoryAxis", orderRule = "Date") +d1$yAxis(type = "addMeasureAxis") +d1$legend( + x = 200, + y = 10, + width = 500, + height = 20, + horizontalAlign = "right" +) +d1 + + +..p.() # ================================ + +## example 30 100% Stacked Area +#just change type for y axis +d1$yAxis( type = "addPctAxis" ) +d1 + + + +..p.() # ================================ + +## example 31 Grouped Area +d1 <- dPlot( + y = "UnitSales", + x = c("Owner","Month"), + groups = "Owner", + data = subset(data, Owner %in% c("Aperture","Black Mesa")), + type = "area" +) +d1$xAxis(type = "addCategoryAxis", grouporderRule = "Date") +d1$yAxis(type = "addMeasureAxis") +d1$legend( + x = 200, + y = 10, + width = 500, + height = 20, + horizontalAlign = "right" +) +d1 + + + +..p.() # ================================ + +## example 32 Grouped Stacked Area +d1 <- dPlot( + y = "UnitSales", + x = c("Owner","Month"), + groups = "SKU", + data = subset(data, Owner %in% c("Aperture","Black Mesa")), + type = "area", + bounds = list(x=70,y=30,height=340,width=330), + barGap = 0.05, + lineWeight = 1, + height = 400, + width = 590 +) +d1$xAxis(type = "addCategoryAxis", grouporderRule = "Date") +d1$yAxis(type = "addMeasureAxis") +d1$legend( + x = 430, + y = 20, + width = 100, + height = 300, + horizontalAlign = "left" +) +d1 + + +..p.() # ================================ + +## example 33 Grouped 100% Area +d1$yAxis( type = "addPctAxis" ) +d1 + + +..p.() # ================================ + +## example 34 Vertical Area +d1 <- dPlot( + x = "UnitSales", + y = "Month", + data = subset(data, Owner %in% c("Aperture","Black Mesa")), + type = "area", + bounds = list(x=80,y=30,height=480,width=330), + height = 400, + width = 590 +) +d1$xAxis(type = "addMeasureAxis") +d1$yAxis(type = "addCategoryAxis", orderRule = "Date") +d1 + + + +..p.() # ================================ + +## example 35 Vertical Stacked Area +d1 <- dPlot( + x = "UnitSales", + y = "Month", + groups = "Channel", + data = subset(data, Owner %in% c("Aperture","Black Mesa")), + type = "area", + bounds = list(x=80,y=30,height=480,width=330), + height = 400, + width = 590 +) +d1$xAxis(type = "addMeasureAxis") +d1$yAxis(type = "addCategoryAxis", grouporderRule = "Date") +d1$legend( + x = 60, + y = 10, + width = 500, + height = 20, + horizontalAlign = "right" +) +d1 + + +..p.() # ================================ + +## example 36 Vertical 100% Stacked Area +d1$xAxis(type = "addPctAxis") +d1 + + +..p.() # ================================ + +## example 37 Vertical Grouped Area +d1 <- dPlot( + x = "UnitSales", + y = c("Owner","Month"), + groups = "Owner", + data = subset(data, Owner %in% c("Aperture","Black Mesa")), + type = "area", + bounds = list(x=90,y=30,height=470,width=330), + lineWeight = 1, + barGap = 0.05, + height = 400, + width = 590 +) +d1$xAxis(type = "addMeasureAxis") +d1$yAxis(type = "addCategoryAxis", grouporderRule = "Date") +d1 + +..p.() # ================================ + +## example 38 Vertical Grouped Stacked Area +d1 <- dPlot( + x = "UnitSales", + y = c("Owner","Month"), + groups = "SKU", + data = subset(data, Owner %in% c("Aperture","Black Mesa")), + type = "area", + bounds = list(x=90,y=30,height=320,width=330), + lineWeight = 1, + barGap = 0.05, + height = 400, + width = 590 +) +d1$xAxis(type = "addMeasureAxis") +d1$yAxis(type = "addCategoryAxis", grouporderRule = "Date") +d1$legend( + x = 430, + y = 20, + width = 100, + height = 300, + horizontalAlign = "left" +) +d1 + + + +..p.() # ================================ + +## example 39 Vertical Group 100% Area +d1$xAxis( type = "addPctAxis" ) +d1 + + + + + +..p.() # ================================ + +## example 40 Line +d1 <- dPlot( + UnitSales ~ Month, + data = subset(data, Owner %in% c("Aperture","Black Mesa")), + type = "line" +) +d1$xAxis(type = "addCategoryAxis", orderRule = "Date") +d1$yAxis(type = "addMeasureAxis") +d1 + + +..p.() # ================================ + +## example 41 Multiple Line +d1 <- dPlot( + UnitSales ~ Month, + groups = "Channel", + data = subset(data, Owner %in% c("Aperture","Black Mesa")), + type = "line" +) +d1$xAxis(type = "addCategoryAxis", orderRule = "Date") +d1$yAxis(type = "addMeasureAxis") +d1$legend( + x = 200, + y = 10, + width = 500, + height = 20, + horizontalAlign = "right" +) +d1 + +..p.() # ================================ + +## example 42 Grouped Single Line +d1 <- dPlot( + y = "UnitSales", + x = c("Owner","Month"), + groups = "Owner", + data = subset(data, Owner %in% c("Aperture","Black Mesa")), + type = "line", + barGap = 0.05 +) +d1$xAxis(type = "addCategoryAxis", grouporderRule = "Date") +d1$yAxis(type = "addMeasureAxis") +d1 + + + +..p.() # ================================ + +## example 43 Grouped Multiple line +d1 <- dPlot( + y = "UnitSales", + x = c("Owner","Month"), + groups = "Brand", + data = subset(data, Owner %in% c("Aperture","Black Mesa")), + type = "line", + bounds = list(x=70,y=30,height=420,width=330), + barGap = 0.05, + height = 400, + width = 590 +) +d1$xAxis(type = "addCategoryAxis", grouporderRule = "Date") +d1$yAxis(type = "addMeasureAxis") +d1$legend( + x = 510, + y = 20, + width = 100, + height = 300, + horizontalAlign = "left" +) +d1 + + + +..p.() # ================================ + +## example 44 Vertical Line +d1 <- dPlot( + x = "UnitSales", + y = "Month", + data = subset(data, Owner %in% c("Aperture","Black Mesa")), + type = "line", + bounds = list(x=80,y=30,height=480,width=330), + height = 400, + width = 590 +) +d1$xAxis(type = "addMeasureAxis") +d1$yAxis(type = "addCategoryAxis", orderRule = "Date") +d1 + + + +..p.() # ================================ + +## example 45 Vertical Multiple Line +d1 <- dPlot( + x = "UnitSales", + y = "Month", + groups = "Channel", + data = subset(data, Owner %in% c("Aperture","Black Mesa")), + type = "line", + bounds = list(x=80,y=30,height=480,width=330), + height = 400, + width = 590 +) +d1$xAxis(type = "addMeasureAxis") +d1$yAxis(type = "addCategoryAxis", orderRule = "Date") +d1$legend( + x = 60, + y = 10, + width = 500, + height = 20, + horizontalAlign = "right" +) +d1 + + + +..p.() # ================================ + +## example 46 Vertical Grouped Line +d1 <- dPlot( + x = "UnitSales", + y = c("Owner","Month"), + groups = "Owner", + data = subset(data, Owner %in% c("Aperture","Black Mesa")), + type = "line", + bounds = list(x=90,y=30,height=470,width=330), + barGap = 0.05, + height = 400, + width = 590 +) +d1$xAxis(type = "addMeasureAxis") +d1$yAxis(type = "addCategoryAxis", grouporderRule = "Date") +d1 + + + +..p.() # ================================ + +## example 47 Vertical Grouped Multi Line +d1 <- dPlot( + x = "UnitSales", + y = c("Owner","Month"), + groups = "Brand", + data = subset(data, Owner %in% c("Aperture","Black Mesa")), + type = "line", + bounds = list(x=90,y=30,height=320,width=330), + barGap = 0.05, + height = 400, + width = 590 +) +d1$xAxis(type = "addMeasureAxis") +d1$yAxis(type = "addCategoryAxis", grouporderRule = "Date") +d1$legend( + x = 430, + y = 20, + width = 100, + height = 300, + horizontalAlign = "left" +) +d1 + + +..p.() # ================================ + +## example 48 timeAxis +data( economics, package = "ggplot2" ) +economics$date = format(economics$date, "%Y-%m-%d") +d1 <- dPlot( +x = "date", +y = "uempmed", +data = economics, +type = "line", +height = 400, +width = 700, +bounds = list(x=50,y=20,width=650,height=300) +) +d1$xAxis( +type = "addTimeAxis", +inputFormat = "%Y-%m-%d", +outputFormat = "%b %Y" +) +d1 + +..p.() # ================================ diff --git a/demo/highcharts.R b/demo/highcharts.R new file mode 100644 index 0000000..48a8f3d --- /dev/null +++ b/demo/highcharts.R @@ -0,0 +1,102 @@ +..p. <- function() invisible(readline("\nPress to continue: ")) +library(rCharts) + +# Example 1 +hPlot(Pulse ~ Height, data = MASS::survey, type = "scatter", group = "Exer") + +..p.() # ================================ + +## Example 2 +a <- hPlot(Pulse ~ Height, data = MASS::survey, type = "bubble", title = "Zoom demo", subtitle = "bubble chart", size = "Age", group = "Exer") +a$chart(zoomType = "xy") +a$exporting(enabled = T) +a + +..p.() # ================================ + +## Example 4 +x <- data.frame(key = c("a", "b", "c"), value = c(1, 2, 3)) +hPlot(x = "key", y = "value", data = x, type = "pie") + +..p.() # ================================ + +## Example 5 +a <- hPlot(Pulse ~ Height, data = MASS::survey, type = 'scatter', group = 'Sex', radius = 6, group.na = "Not Available") +a$colors('rgba(223, 83, 83, .5)', 'rgba(119, 152, 191, .5)', 'rgba(60, 179, 113, .5)') +a$legend(align = 'right', verticalAlign = 'top', layout = 'vertical') +a$plotOptions(scatter = list(marker = list(symbol = 'circle'))) +a$tooltip(formatter = "#! function() { return this.x + ', ' + this.y; } !#") +a + +..p.() # ================================ + +## Example 6 +hPlot(freq ~ Exer, data = plyr::count(MASS::survey, c('Sex', 'Exer')), type = c('column', 'line'), group = 'Sex', radius = 6) + +..p.() # ================================ + +## Example 7 +hPlot(freq ~ Exer, data = plyr::count(MASS::survey, c('Sex', 'Exer')), type = 'bar', group = 'Sex', group.na = 'NA\'s') + +..p.() # ================================ + +## Example 8 +a <- hPlot(freq ~ Exer, data = plyr::count(MASS::survey, c('Sex', 'Exer')), type = 'column', group = 'Sex', group.na = 'NA\'s') +a$plotOptions(column = list(dataLabels = list(enabled = T, rotation = -90, align = 'right', color = '#FFFFFF', x = 4, y = 10, style = list(fontSize = '13px', fontFamily = 'Verdana, sans-serif')))) +a$xAxis(labels = list(rotation = -45, align = 'right', style = list(fontSize = '13px', fontFamily = 'Verdana, sans-serif')), replace = F) +a + +..p.() # ================================ + +## Example 9 (not working properly) +drill_function <- "#! function() { + var drilldown = this.drilldown; + function setChart(name, categories, data, color) { + chart.xAxis[0].setCategories(categories, false); + chart.series[0].remove(false); + chart.addSeries({ + name: name, + data: data, + color: color || 'black' + }, false); + chart.redraw(); + }; + if (drilldown) { // drill down + setChart(drilldown.name, drilldown.categories, drilldown.data, drilldown.color); + } else { // restore + setChart(name, categories, data); + } +} !#" + +a <- rCharts::Highcharts$new() +a$chart(type = "column") +a$series(data = list( + list(y = 15, drilldown = list(data = c(1, 2, 3))), + list(y = 20, drilldown = list(data = c(1, 2, 3)))), name = "test") +a$xAxis(categories = c("Brand A", "Brand B")) +a$plotOptions(column = list(cursor = 'pointer', point = list(events = list(click = drill_function)))) +a + +..p.() # ================================ + +## Example 10 +a <- hPlot(freq ~ Exer, data = plyr::count(MASS::survey, c('Sex', 'Exer')), type = 'bar', group = 'Sex', group.na = 'NA\'s') +a$plotOptions(bar = list(cursor = 'pointer', point = list(events = list(click = "#! function() { alert ('Category: '+ this.category +', value: '+ this.y); } !#")))) +a + +..p.() # ================================ + +## Example 11 +a <- rCharts::Highcharts$new() +a$series(data = list( + list(y = 8, url = "https://github.com/metagraf/rHighcharts", color = "lightblue"), + list(y = 14, url = "https://github.com/metagraf/rVega", color = "lightpink"), + list(y = 71, url = "https://github.com/ramnathv/rCharts", color = "lightgreen") +), type = "column", name = "Number of Stars") +a$plotOptions(column = list(cursor = 'pointer', point = list(events = list(click = "#! function() { location.href = this.options.url; } !#")))) +a$xAxis(categories = c("rHighcharts", "rVega", "rCharts"), title = list(text = "")) +a$yAxis(title = list(text = "")) +a$legend(enabled = F) +a + +..p.() # ================================ diff --git a/demo/leaflet.R b/demo/leaflet.R new file mode 100644 index 0000000..90ca168 --- /dev/null +++ b/demo/leaflet.R @@ -0,0 +1,206 @@ +..p. <- function() invisible(readline("\nPress to continue: ")) +require(rCharts) + +map1 = Leaflet$new() +map1$setView(c(45.5236, -122.675), 13) +map1$tileLayer("http://a.tiles.mapbox.com/v3/mapbox.control-room/{z}/{x}/{y}.png", zoom = 8) +map1 + +..p.() # ================================ + +map1 = Leaflet$new() +map1$setView(c(45.50867, -73.55399), 13) +map1 + +..p.() # ================================ + +map2 = Leaflet$new() +map2$setView(c(45.5236, -122.675), 10) +map2$tileLayer("http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png") +map2 + +..p.() # ================================ + +map3 <- Leaflet$new() +map3$setView(c(51.505, -0.09), zoom = 13) +map3$tileLayer( + "http://{s}.tile.cloudmade.com/BC9A493B41014CAABB98F0471D759707/997/256/{z}/{x}/{y}.png", + maxZoom = 18 +) +map3$marker(c(51.5, -0.09), bindPopup = "

Hi. I am a popup

") +map3$marker(c(51.495, -0.083), bindPopup = "

Hi. I am another popup

") +map3$show(cdn = T) + +map3$circle(c(51.5, -0.09)) + +..p.() # ================================ + +map4 = Leaflet$new() +map4$setView(c(29.6779, -95.4379), 10) +map4$tileLayer("http://{s}.tile.cloudmade.com/BC9A493B41014CAABB98F0471D759707/997/256/{z}/{x}/{y}.png") +# map4$tileLayer(provider = 'Stamen.Terrain') + +data(crime, package = 'ggmap') +dat <- head(crime)[,c('lat', 'lon', 'offense')] +names(dat) <- c('lat', 'lng', 'offense') +map4$geocsv(dat) +map4 + +..p.() # ================================ + +#map5 = Leaflet$new() +#map5$setView(37.27667, -91.60611, 4) +#map5$tileLayer("http://{s}.tile.cloudmade.com/BC9A493B41014CAABB98F0471D759707/997/256/{z}/{x}/{y}.png") +# +#dat <- read.csv('geoCoded.csv') +#names(dat) <- c('address', 'lat', 'lng') +#dat <- transform(dat, color = 'red', fillColor = '#f03', fillOpacity = 0.5, radius = 10) +#map5$circle(dat) +#map5 + +..p.() # ================================ + +rMap <- function(location = 'montreal', zoom = 10, provider = 'MapQuestOpen.OSM'){ + m1 <- Leaflet$new() + lnglat <- as.list(ggmap::geocode(location)) + m1$setView(lnglat$lat, lnglat$lon, zoom = zoom) + m1$tileLayer(provider = provider) + return(m1) +} + +r1 <- rMap() +mcgill <- as.list(ggmap::geocode('mcgill univesity')) +r1$marker(mcgill$lat, mcgill$lon, bindPopup = 'mcgill university') +r1 + +..p.() # ================================ + +map6 = Leaflet$new() +map6$setView(45.372, -121.6972, 12) +map6$tileLayer(provider ='Stamen.Terrain') +map6$marker(45.3288, -121.6625, bindPopup = 'Mt. Hood Meadows') +map6$marker(45.3311, -121.7113, bindPopup = 'Timberline Lodge') + +..p.() # ================================ + +map1b = Leaflet$new() +map1b$setView(c(45.5236, -122.675), zoom = 14) +map1b$tileLayer(provider = 'MapQuestOpen.OSM') +map1b + +..p.() # ================================ + +map3 <- Leaflet$new() +map3$setView(c(51.505, -0.09), zoom = 13) +map3$tileLayer( + "http://{s}.tile.cloudmade.com/BC9A493B41014CAABB98F0471D759707/997/256/{z}/{x}/{y}.png", + maxZoom = 18 +) +map3$circle(c(51.5, -0.09), 100) + +..p.() # ================================ + +map2 = Leaflet$new() +map2$setView(c(45.5236, -122.6750), 13) +map2$tileLayer(provider = 'Stamen.Toner') +map2$marker(c(45.5244, -122.6699), bindPopup = 'The Waterfront') +map2$circle(c(45.5215, -122.6261), radius = 500, bindPopup = 'Laurelhurst Park') +map2 + +..p.() # ================================ + +# devtools::install_github('rCharts', 'bbest') # tweak to make var geojsonLayer available +json = '{"type":"FeatureCollection","features":[ + {"type":"Feature", + "properties":{"region_id":1, "region_name":"Australian Alps"}, + "geometry":{"type":"Polygon","coordinates":[[[141.13037109375,-38.788345355085625],[141.13037109375,-36.65079252503469],[144.38232421875,-36.65079252503469],[144.38232421875,-38.788345355085625],[141.13037109375,-38.788345355085625]]]}}, + {"type":"Feature", + "properties":{"region_id":4, "region_name":"Shark Bay"}, + "geometry":{"type":"Polygon","coordinates":[[[143.10791015625,-37.75334401310656],[143.10791015625,-34.95799531086791],[146.25,-34.95799531086791],[146.25,-37.75334401310656],[143.10791015625,-37.75334401310656]]]}} + ]}' +regions=RJSONIO::fromJSON(json) + +lmap <- Leaflet$new() +lmap$tileLayer(provide='Stamen.TonerLite') +lmap$setView(c(-37, 145), zoom = 6) +lmap$geoJson( + regions, + style = "#! function(feature) { + var rgn2col = {1:'red',2:'blue',4:'green'}; + return { + color: rgn2col[feature.properties['region_id']], + strokeWidth: '1px', + strokeOpacity: 0.5, + fillOpacity: 0.2 + }; } !#", + onEachFeature = "#! function (feature, layer) { + + // info rollover + if (document.getElementsByClassName('info leaflet-control').length == 0 ){ + info = L.control({position: 'topright'}); // NOTE: made global b/c not ideal place to put this function + info.onAdd = function (map) { + this._div = L.DomUtil.create('div', 'info'); + this.update(); + return this._div; + }; + info.update = function (props) { + this._div.innerHTML = '

Field Name

' + (props ? + props['region_id'] + ': + props[fld] + ' + : 'Hover over a region'); + }; + info.addTo(map); + }; + + // mouse events + layer.on({ + + // mouseover to highlightFeature + mouseover: function (e) { + var layer = e.target; + layer.setStyle({ + strokeWidth: '3px', + strokeOpacity: 0.7, + fillOpacity: 0.5 + }); + if (!L.Browser.ie && !L.Browser.opera) { + layer.bringToFront(); + } + info.update(layer.feature.properties); + }, + + // mouseout to resetHighlight + mouseout: function (e) { + geojsonLayer.resetStyle(e.target); + info.update(); + }, + + // click to zoom + click: function (e) { + var layer = e.target; + if ( feature.geometry.type === 'MultiPolygon' ) { + // for multipolygons get true extent + var bounds = layer.getBounds(); // get the bounds for the first polygon that makes up the multipolygon + // loop through coordinates array, skip first element as the bounds var represents the bounds for that element + for ( var i = 1, il = feature.geometry.coordinates[0].length; i < il; i++ ) { + var ring = feature.geometry.coordinates[0][i]; + var latLngs = ring.map(function(pair) { + return new L.LatLng(pair[1], pair[0]); + }); + var nextBounds = new L.LatLngBounds(latLngs); + bounds.extend(nextBounds); + } + map.fitBounds(bounds); + } else { + // otherwise use native target bounds + map.fitBounds(e.target.getBounds()); + } + } + }); + } !#") +legend_vec = c('red'='high', 'blue'='medium', 'green'='low') +lmap$legend(position = 'bottomright', + colors = names(legend_vec), + labels = as.vector(legend_vec)) +lmap + +..p.() # ================================ diff --git a/demo/morris.R b/demo/morris.R new file mode 100644 index 0000000..7680f59 --- /dev/null +++ b/demo/morris.R @@ -0,0 +1,43 @@ +..p. <- function() invisible(readline("\nPress to continue: ")) +library(rCharts) + +haireye <- as.data.frame(HairEyeColor) + +## {title: Simple Bar Chart} +dat <- subset(haireye, Sex == "Female" & Eye == "Blue") +p1 <- mPlot(x = 'Hair', y = list('Freq'), data = dat, type = 'Bar', labels = list("Count")) +p1 + +..p.() # ================================ + +### {title: Simple Bar Chart, tag: "No Hover"} +p1$set(hideHover = "auto") +p1 + +..p.() # ================================ + +## {title: Multi Bar Chart} +dat <- subset(haireye, Sex == "Female") +p2 <- mPlot(Freq ~ Eye, group = "Hair", data = dat, type = "Bar", labels = 1:4) +p2 + +..p.() # ================================ + +## {title: Line Chart} +data(economics, package = 'ggplot2') +dat <- transform(economics, date = as.character(date)) +p3 <- mPlot(x = "date", y = list("psavert", "uempmed"), data = dat, type = 'Line', + pointSize = 0, lineWidth = 1) +p3$set(xLabelFormat = "#! function (x) { + return x.toString(); } +!#") +p3 + +..p.() # ================================ + +## {title: Area Chart} +p3$set(type = 'Area') +p3 + +..p.() # ================================ + diff --git a/demo/nvd3.R b/demo/nvd3.R new file mode 100644 index 0000000..b8bbf2f --- /dev/null +++ b/demo/nvd3.R @@ -0,0 +1,196 @@ +..p. <- function() invisible(readline("\nPress to continue: ")) +library(rCharts) + +## {title: Scatter Chart} +p1 <- nPlot(mpg ~ wt, group = 'cyl', data = mtcars, type = 'scatterChart') +p1$xAxis(axisLabel = 'Weight') +p1 + +..p.() # ================================ + +## {title: MultiBar Chart} +hair_eye = as.data.frame(HairEyeColor) +p2 <- nPlot(Freq ~ Hair, group = 'Eye', data = subset(hair_eye, Sex == "Female"), type = 'multiBarChart') +p2$chart(color = c('brown', 'blue', '#594c26', 'green')) +p2 + +..p.() # ================================ + +## {title: MultiBar Horizontal Chart} +p3 <- nPlot(~ cyl, group = 'gear', data = mtcars, type = 'multiBarHorizontalChart') +p3$chart(showControls = F) +p3 + +..p.() # ================================ + +## {title: Pie Chart} +p4 <- nPlot(~ cyl, data = mtcars, type = 'pieChart') +p4 + +..p.() # ================================ + +## {title: Donut Chart} +p5 <- nPlot(~ cyl, data = mtcars, type = 'pieChart') +p5$chart(donut = TRUE) +p5 + +..p.() # ================================ + +## {title: Line Chart} +data(economics, package = 'ggplot2') +p6 <- nPlot(uempmed ~ date, data = economics, type = 'lineChart') +p6 + +..p.() # ================================ + +## {title: Line with Focus Chart } +ecm <- reshape2::melt(economics[,c('date', 'uempmed', 'psavert')], id = 'date') +p7 <- nPlot(value ~ date, group = 'variable', data = ecm, type = 'lineWithFocusChart') +#test format dates on the xAxis +#also good test of javascript functions as parameters +#dates from R to JSON will come over as number of days since 1970-01-01 +#so convert to milliseconds 86400000 in a day and then format with d3 +#on lineWithFocusChart type xAxis will also set x2Axis unless it is specified +p7$xAxis( tickFormat="#!function(d) {return d3.time.format('%b %Y')(new Date( d * 86400000 ));}!#" ) +#test xAxis also sets x2Axis +p7 + +..p.() # ================================ + +#now test setting x2Axis to something different +#test format dates on the x2Axis +#test to show %Y format which is different than xAxis +p7$x2Axis( tickFormat="#!function(d) {return d3.time.format('%Y')(new Date( d * 86400000 ));}!#" ) +p7 + +..p.() # ================================ + +#test set xAxis again to make sure it does not override set x2Axis +p7$xAxis( NULL, replace = T) +p7 + +..p.() # ================================ + +## {title: Stacked Area Chart} +dat <- data.frame(t=rep(0:23,each=4),var=rep(LETTERS[1:4],4),val=round(runif(4*24,0,50))) +p8 <- nPlot(val ~ t, group = 'var', data = dat, type = 'stackedAreaChart', id = 'chart') +p8 + + +..p.() # ================================ + +## {title: InteractiveGuidline(Multi-Tooltips) on Line} +p9 <- nPlot(value ~ date, group = 'variable', data = ecm, type = 'lineChart') +p9$xAxis( tickFormat="#!function(d) {return d3.time.format('%b %Y')(new Date( d * 86400000 ));}!#" ) +#try new interactive guidelines feature +p9$chart(useInteractiveGuideline=TRUE) +p9 + + +..p.() # ================================ + +## {title: InteractiveGuidline(Multi-Tooltips) on Stack} +p10 <- p8 +p10$chart(useInteractiveGuideline=TRUE) +p10 + +..p.() # ================================ + +## {title: showDistX and showDistY} +p11 <- p1 +p11$chart(showDistX = TRUE, showDistY = TRUE) +p11 + +..p.() # ================================ + +## {title: multiChart} +p12 <- nPlot(value ~ date, group = 'variable', data = ecm, type = 'multiChart') +p12$params$multi = list( + uempmed = list(type="area",yAxis=1), + psavert = list(type="line",yAxis=2) +) +p12$setTemplate(script = system.file( + "/libraries/nvd3/layouts/multiChart.html", + package = "rCharts" +)) +p12 + +..p.() # ================================ + +## ## {title: Facets} +## facet has not been supported yet. +## +## p13 <- nPlot(mpg ~ wt, data = mtcars, group = "gear", type = "scatterChart") +## p13$params$facet = "cyl" +## p13$templates$script = system.file( +## "/libraries/nvd3/layouts/nvd3FacetPlot.html", +## package = "rCharts" +## ) +## p13 +## +## ..p.() # ================================ +## +## hair_eye = as.data.frame(HairEyeColor) +## p14 <- nPlot(Freq ~ Hair, group = 'Sex', data = hair_eye, type = 'multiBarChart') +## p14$params$facet="Eye" +## p14$templates$script = system.file( +## "/libraries/nvd3/layouts/nvd3FacetPlot.html", +## package = "rCharts" +## ) +## p14 +## +## ..p.() # ================================ +## +## p15 <- nPlot(Freq ~ Hair, group = 'Eye', data = hair_eye, type = 'multiBarChart') +## p15$params$facet="Sex" +## p15$templates$script = system.file( +## "/libraries/nvd3/layouts/nvd3FacetPlot.html", +## package = "rCharts" +## ) +## p15 +## +## ..p.() # ================================ + +## {title: Sparklines} +p16 <- nPlot(uempmed ~ date, data = economics, type = 'sparklinePlus',height=100,width=500) +p16$chart(xTickFormat="#!function(d) {return d3.time.format('%b %Y')(new Date( d * 86400000 ));}!#") +p16 + +..p.() # ================================ + +## semi replicate sparkline with a full nvd3 model by setting short height and turning off lots of things +require(quantmod) + +spy <- getSymbols("SPY",auto.assign=FALSE,from="2013-01-01") +colnames(spy) <- c("open","high","low","close","volume","adjusted") + +spy.df <- data.frame(index(spy),spy) +colnames(spy.df)[1] <- "date" + +p17 <- nPlot( + x = "date", + y = "volume", + data = spy.df, + type = "multiBarChart", + height = 200) +p17$chart(showControls = FALSE, showLegend = FALSE, showXAxis = FALSE, showYAxis = FALSE) +p17$xAxis(tickFormat = + "#!function(d) {return d3.time.format('%Y-%m-%d')(new Date(d * 24 * 60 * 60 * 1000));}!#" +) +p17 + + +..p.() # ================================ + +## {title: ohlcBar} +## ohlcBar not fully implemented on nvd3 side, so no axes or interactive controls +## note do not melt if using ohlcBar +p18 <- nPlot( + x = "date", + y = "close", + data = spy.df, + type = "ohlcBar" +) +p18 + +..p.() # ================================ diff --git a/demo/polycharts.R b/demo/polycharts.R new file mode 100644 index 0000000..ee34962 --- /dev/null +++ b/demo/polycharts.R @@ -0,0 +1,53 @@ +..p. <- function() invisible(readline("\nPress to continue: ")) +library(rCharts) + +## Example 1 Facetted Scatterplot +names(iris) = gsub("\\.", "", names(iris)) +p1 <- rPlot(SepalLength ~ SepalWidth | Species, data = iris, color = 'Species', type = 'point') +p1 +p1$show(cdn = T) +# p1$show(static = F) + +..p.() # ================================ + +## Example 2 Facetted Barplot +hair_eye = as.data.frame(HairEyeColor) +p2 <- rPlot(Freq ~ Hair, color = 'Eye', data = hair_eye, type = 'bar') +p2$facet(var = 'Eye', type = 'wrap', rows = 2) +p2 + +..p.() # ================================ + +## Example 3 Boxplot +data(tips, package = 'reshape2') +p3 <- rPlot(x = 'day', y = 'box(tip)', data = tips, type = 'box') +p3 + +..p.() # ================================ + +## Example 4 +require(plyr) +dat = count(mtcars, .(gear, am)) +p4 <- rPlot(x = 'bin(gear, 1)', y = 'freq', data = dat, type = 'bar', + list(var = 'am', type = 'wrap')) +p4 + +..p.() # ================================ + +## Example 5 (Heat Map) +dat = expand.grid(x = 1:5, y = 1:5) +dat = transform(dat, value = sample(1:5, 25, replace = T)) +p5 <- rPlot(x = 'bin(x, 1)', y = 'bin(y, 1)', color = 'value', data = dat, type = 'tile') +p5 + +..p.() # ================================ + +# Example 6 (NBA Heat Map) +require(reshape2); require(scales); require(plyr) +nba <- read.csv('http://datasets.flowingdata.com/ppg2008.csv') +nba.m <- ddply(melt(nba), .(variable), transform, rescale = rescale(value)) +p6 <- rPlot(Name ~ variable, color = 'rescale', data = nba.m, type = 'tile', height = 600) +p6$guides("{color: {scale: {type: gradient, lower: white, upper: steelblue}}}") +p6 + +..p.() # ================================ diff --git a/demo/rickshaw.R b/demo/rickshaw.R new file mode 100644 index 0000000..daf590a --- /dev/null +++ b/demo/rickshaw.R @@ -0,0 +1,91 @@ +..p. <- function() invisible(readline("\nPress to continue: ")) +library(rCharts) + +require(quantmod) +require(plyr) +tickers = c('AAPL', 'GOOG', 'MSFT') +quotes = llply(tickers, getSymbols, auto.assign = F) + +to_jsdate <- function(date_){ + val = as.POSIXct(as.Date(date_), origin="1970-01-01") + as.numeric(val) +} + +getSymbols('AAPL') +AAPL <- transform(AAPL, date = to_jsdate(index(AAPL))) +names(AAPL) = gsub(".", "_", names(AAPL), fixed = TRUE) + +options(RCHART_TEMPLATE = 'Rickshaw.html') +r1 <- Rickshaw$new() +r1$layer(x = 'date', y = 'AAPL_Open', data = AAPL, type = 'line', colors = 'steelblue') +r1$xAxis(type = 'Time') +r1$yAxis(orientation = 'left') + +riPlot <- function(x, y, data, type, ..., xAxis = list(type = 'Time'), + yAxis = list(orientation = 'left')){ + options(RCHART_TEMPLATE = 'Rickshaw.html') + r1 <- Rickshaw$new() + r1$layer(x = x, y = y, data = data, type = type, ...) + do.call(r1$xAxis, xAxis) + do.call(r1$yAxis, yAxis) + return(r1) +} + +# Example 1 +p1 <- Rickshaw$new() +p1$layer(~ cyl, group = 'am', data = mtcars, type = 'bar') +p1 + +..p.() # ================================ + +# Example 2 +require(RColorBrewer) +data(economics, package = 'ggplot2') +datm = reshape2::melt( + economics[,c('date', 'psavert', 'uempmed')], + id = 'date' +) +datm <- transform(datm, date = to_jsdate(date)) +p2 <- Rickshaw$new() +p2$layer(value ~ date, group = 'variable', data = datm, type = 'line', + colors = c("darkred", "darkslategrey")) +p2 + +..p.() # ================================ + +p3 <- Rickshaw$new() +p3$layer(Employed ~ Year, data = longley, type = 'line', colors = c('darkred')) +p3 + +..p.() # ================================ + +usp = reshape2::melt(USPersonalExpenditure) +p4 <- Rickshaw$new() +p4$layer(value ~ Var2, group = 'Var1', data = usp, type = 'area') +p4$show(T) + +..p.() # ================================ + +data(USPop, package = 'car') +dat <- USPop +dat <- transform(dat, year = to_jsdate(as.Date(paste(year, '01', '01', sep = '-')))) +p4 <- Rickshaw$new() +p4$layer(population ~ year, data = dat, type = 'area', colors = 'steelblue') +p4$yAxis(orientation = 'right') +p4$set(width = 540, height = 240) +p4 + +..p.() # ================================ + +uspexp <- reshape2::melt(USPersonalExpenditure) +names(uspexp) <- c('category', 'year', 'expenditure') +uspexp <- transform(uspexp, year = to_jsdate(as.Date(paste(year, '01', '01', sep = '-')))) +p4 <- Rickshaw$new() +p4$layer(expenditure ~ year, group = 'category', data = uspexp, type = 'area') +p4$yAxis(orientation = 'left') +p4$xAxis(type = 'Time') +p4$set(width = 540, height = 240) + +p4 + +..p.() # ================================ diff --git a/demo/xcharts.R b/demo/xcharts.R new file mode 100644 index 0000000..f5cee8b --- /dev/null +++ b/demo/xcharts.R @@ -0,0 +1,30 @@ +..p. <- function() invisible(readline("\nPress to continue: ")) +library(rCharts) +options(RCHART_WIDTH = 800, RCHART_HEIGHT = 400) + +### {title: Bar Chart, working: FALSE} +p1 <- xCharts$new() +p1$set(xScale = 'ordinal', yScale = 'linear') +p1$layer(~ cyl, data = mtcars, type = 'bar') +p1 + +..p.() # ================================ + +### {title: Multi Bar Chart, working: TRUE} +haireye = subset(as.data.frame(HairEyeColor), Sex == "Male") +p2 <- xCharts$new() +p2$set(xScale = 'ordinal', yScale = 'linear', width = 600) +p2$layer(Freq ~ Hair, group = 'Eye', data = haireye, type = 'bar') +p2 + +..p.() # ================================ + +### {title: Line Chart, working: TRUE} +uspexp = reshape2::melt(USPersonalExpenditure) +names(uspexp)[1:2] = c('Category', 'Year') +p3 <- xCharts$new() +p3$layer(value ~ Year, group = 'Category', data = uspexp) +p3$set(xScale = 'linear', yScale = 'linear', type = 'line-dotted', xMin = 1935) +p3 + +..p.() # ================================