title |
subtitle |
layout |
output |
Data Viz Comparison |
base vs ggplot2 vs ggvis vs googleVis vs rCharts vs plotly vs ggplotly |
page |
|
http://www.statmethods.net/graphs/
plot(iris$Sepal.Length, iris$Petal.Length, # x variable, y variable
col = iris$Species, # colour by species
pch = 16, # type of point to use
cex = 1, # size of point to use
xlab = "Sepal Length", # x axis label
ylab = "Petal Length", # y axis label
main = "Flower Characteristics in Iris") # plot title
legend (x = 4.5, y = 7, legend = levels(iris$Species), col = c(1:3), pch = 16)
![plot of chunk base]({{ site.url }}/post_data/data-viz-compare-base-1.png)
http://ggplot2.org/
library(ggplot2)
gg <- ggplot(iris) +
geom_point(aes(x=Sepal.Length, y=Petal.Length, color = Species)) +
labs(title = "Flower Characteristics in Iris", x = "Sepal Length", y = "Petal Length")
gg
![plot of chunk ggplot2]({{ site.url }}/post_data/data-viz-compare-ggplot2-1.png)
http://ggvis.rstudio.com/
library(ggvis)
data(iris)
# hack for title from: http://stackoverflow.com/questions/25018598/add-a-plot-title-to-ggvis
add_title <- function(vis, ..., x_lab = "X units", title = "Plot Title") {
add_axis(vis, "x", title = x_lab) %>%
add_axis("x", orient = "top", ticks = 0, title = title,
properties = axis_props(
axis = list(stroke = "white"),
labels = list(fontSize = 0)
), ...)
}
p <- ggvis(iris, x = ~Sepal.Length, y = ~Petal.Length, fill = ~Species) %>% add_title(title = "Flower Characteristics in Iris",
x_lab = "Sepal.Length")
layer_points(p)
<script type="text/javascript">
var plot_id731364669_spec = {
"data": [
{
"name": "iris0",
"format": {
"type": "csv",
"parse": {
"Sepal.Length": "number",
"Petal.Length": "number"
}
},
"values": "\"Sepal.Length\",\"Petal.Length\",\"Species\"\n5.1,1.4,\"setosa\"\n4.9,1.4,\"setosa\"\n4.7,1.3,\"setosa\"\n4.6,1.5,\"setosa\"\n5,1.4,\"setosa\"\n5.4,1.7,\"setosa\"\n4.6,1.4,\"setosa\"\n5,1.5,\"setosa\"\n4.4,1.4,\"setosa\"\n4.9,1.5,\"setosa\"\n5.4,1.5,\"setosa\"\n4.8,1.6,\"setosa\"\n4.8,1.4,\"setosa\"\n4.3,1.1,\"setosa\"\n5.8,1.2,\"setosa\"\n5.7,1.5,\"setosa\"\n5.4,1.3,\"setosa\"\n5.1,1.4,\"setosa\"\n5.7,1.7,\"setosa\"\n5.1,1.5,\"setosa\"\n5.4,1.7,\"setosa\"\n5.1,1.5,\"setosa\"\n4.6,1,\"setosa\"\n5.1,1.7,\"setosa\"\n4.8,1.9,\"setosa\"\n5,1.6,\"setosa\"\n5,1.6,\"setosa\"\n5.2,1.5,\"setosa\"\n5.2,1.4,\"setosa\"\n4.7,1.6,\"setosa\"\n4.8,1.6,\"setosa\"\n5.4,1.5,\"setosa\"\n5.2,1.5,\"setosa\"\n5.5,1.4,\"setosa\"\n4.9,1.5,\"setosa\"\n5,1.2,\"setosa\"\n5.5,1.3,\"setosa\"\n4.9,1.4,\"setosa\"\n4.4,1.3,\"setosa\"\n5.1,1.5,\"setosa\"\n5,1.3,\"setosa\"\n4.5,1.3,\"setosa\"\n4.4,1.3,\"setosa\"\n5,1.6,\"setosa\"\n5.1,1.9,\"setosa\"\n4.8,1.4,\"setosa\"\n5.1,1.6,\"setosa\"\n4.6,1.4,\"setosa\"\n5.3,1.5,\"setosa\"\n5,1.4,\"setosa\"\n7,4.7,\"versicolor\"\n6.4,4.5,\"versicolor\"\n6.9,4.9,\"versicolor\"\n5.5,4,\"versicolor\"\n6.5,4.6,\"versicolor\"\n5.7,4.5,\"versicolor\"\n6.3,4.7,\"versicolor\"\n4.9,3.3,\"versicolor\"\n6.6,4.6,\"versicolor\"\n5.2,3.9,\"versicolor\"\n5,3.5,\"versicolor\"\n5.9,4.2,\"versicolor\"\n6,4,\"versicolor\"\n6.1,4.7,\"versicolor\"\n5.6,3.6,\"versicolor\"\n6.7,4.4,\"versicolor\"\n5.6,4.5,\"versicolor\"\n5.8,4.1,\"versicolor\"\n6.2,4.5,\"versicolor\"\n5.6,3.9,\"versicolor\"\n5.9,4.8,\"versicolor\"\n6.1,4,\"versicolor\"\n6.3,4.9,\"versicolor\"\n6.1,4.7,\"versicolor\"\n6.4,4.3,\"versicolor\"\n6.6,4.4,\"versicolor\"\n6.8,4.8,\"versicolor\"\n6.7,5,\"versicolor\"\n6,4.5,\"versicolor\"\n5.7,3.5,\"versicolor\"\n5.5,3.8,\"versicolor\"\n5.5,3.7,\"versicolor\"\n5.8,3.9,\"versicolor\"\n6,5.1,\"versicolor\"\n5.4,4.5,\"versicolor\"\n6,4.5,\"versicolor\"\n6.7,4.7,\"versicolor\"\n6.3,4.4,\"versicolor\"\n5.6,4.1,\"versicolor\"\n5.5,4,\"versicolor\"\n5.5,4.4,\"versicolor\"\n6.1,4.6,\"versicolor\"\n5.8,4,\"versicolor\"\n5,3.3,\"versicolor\"\n5.6,4.2,\"versicolor\"\n5.7,4.2,\"versicolor\"\n5.7,4.2,\"versicolor\"\n6.2,4.3,\"versicolor\"\n5.1,3,\"versicolor\"\n5.7,4.1,\"versicolor\"\n6.3,6,\"virginica\"\n5.8,5.1,\"virginica\"\n7.1,5.9,\"virginica\"\n6.3,5.6,\"virginica\"\n6.5,5.8,\"virginica\"\n7.6,6.6,\"virginica\"\n4.9,4.5,\"virginica\"\n7.3,6.3,\"virginica\"\n6.7,5.8,\"virginica\"\n7.2,6.1,\"virginica\"\n6.5,5.1,\"virginica\"\n6.4,5.3,\"virginica\"\n6.8,5.5,\"virginica\"\n5.7,5,\"virginica\"\n5.8,5.1,\"virginica\"\n6.4,5.3,\"virginica\"\n6.5,5.5,\"virginica\"\n7.7,6.7,\"virginica\"\n7.7,6.9,\"virginica\"\n6,5,\"virginica\"\n6.9,5.7,\"virginica\"\n5.6,4.9,\"virginica\"\n7.7,6.7,\"virginica\"\n6.3,4.9,\"virginica\"\n6.7,5.7,\"virginica\"\n7.2,6,\"virginica\"\n6.2,4.8,\"virginica\"\n6.1,4.9,\"virginica\"\n6.4,5.6,\"virginica\"\n7.2,5.8,\"virginica\"\n7.4,6.1,\"virginica\"\n7.9,6.4,\"virginica\"\n6.4,5.6,\"virginica\"\n6.3,5.1,\"virginica\"\n6.1,5.6,\"virginica\"\n7.7,6.1,\"virginica\"\n6.3,5.6,\"virginica\"\n6.4,5.5,\"virginica\"\n6,4.8,\"virginica\"\n6.9,5.4,\"virginica\"\n6.7,5.6,\"virginica\"\n6.9,5.1,\"virginica\"\n5.8,5.1,\"virginica\"\n6.8,5.9,\"virginica\"\n6.7,5.7,\"virginica\"\n6.7,5.2,\"virginica\"\n6.3,5,\"virginica\"\n6.5,5.2,\"virginica\"\n6.2,5.4,\"virginica\"\n5.9,5.1,\"virginica\""
},
{
"name": "scale/fill",
"format": {
"type": "csv",
"parse": {}
},
"values": "\"domain\"\n\"setosa\"\n\"versicolor\"\n\"virginica\""
},
{
"name": "scale/x",
"format": {
"type": "csv",
"parse": {
"domain": "number"
}
},
"values": "\"domain\"\n4.12\n8.08"
},
{
"name": "scale/y",
"format": {
"type": "csv",
"parse": {
"domain": "number"
}
},
"values": "\"domain\"\n0.705\n7.195"
}
],
"scales": [
{
"name": "fill",
"type": "ordinal",
"domain": {
"data": "scale/fill",
"field": "data.domain"
},
"points": true,
"sort": false,
"range": "category10"
},
{
"name": "x",
"domain": {
"data": "scale/x",
"field": "data.domain"
},
"zero": false,
"nice": false,
"clamp": false,
"range": "width"
},
{
"name": "y",
"domain": {
"data": "scale/y",
"field": "data.domain"
},
"zero": false,
"nice": false,
"clamp": false,
"range": "height"
}
],
"marks": [
{
"type": "symbol",
"properties": {
"update": {
"size": {
"value": 50
},
"x": {
"scale": "x",
"field": "data.Sepal\\.Length"
},
"y": {
"scale": "y",
"field": "data.Petal\\.Length"
},
"fill": {
"scale": "fill",
"field": "data.Species"
}
},
"ggvis": {
"data": {
"value": "iris0"
}
}
},
"from": {
"data": "iris0"
}
}
],
"legends": [
{
"orient": "right",
"fill": "fill",
"title": "Species"
}
],
"axes": [
{
"type": "x",
"scale": "x",
"orient": "bottom",
"title": "Sepal.Length",
"layer": "back",
"grid": true
},
{
"type": "x",
"scale": "x",
"orient": "top",
"title": "Flower Characteristics in Iris",
"ticks": 0,
"layer": "back",
"grid": true,
"properties": {
"labels": {
"fontSize": {
"value": 0
}
},
"axis": {
"stroke": {
"value": "white"
}
}
}
},
{
"type": "y",
"scale": "y",
"orient": "left",
"layer": "back",
"grid": true,
"title": "Petal.Length"
}
],
"padding": null,
"ggvis_opts": {
"keep_aspect": false,
"resizable": true,
"padding": {},
"duration": 250,
"renderer": "svg",
"hover_duration": 0,
"width": 504,
"height": 504
},
"handlers": null
};
ggvis.getPlot("plot_id731364669").parseSpec(plot_id731364669_spec);
</script>
https://github.com/mages/googleVis#googlevis
suppressPackageStartupMessages(library(googleVis))
op <- options(gvis.plot.tag = "chart")
options(op)
iris2 = iris[, c("Sepal.Length", "Petal.Length")]
i <- sapply(iris2, is.factor)
iris2[i] <- lapply(iris2[i], as.character)
flower <- gvisScatterChart(iris2, options = list(title = "Flower Characteristics in Iris"))
# plot(flower)
print(flower, "chart")
<script type="text/javascript">
// jsData
function gvisDataScatterChartID116e13813ab4 () {
var data = new google.visualization.DataTable();
var datajson =
[
[
5.1,
1.4
],
[
4.9,
1.4
],
[
4.7,
1.3
],
[
4.6,
1.5
],
[
5,
1.4
],
[
5.4,
1.7
],
[
4.6,
1.4
],
[
5,
1.5
],
[
4.4,
1.4
],
[
4.9,
1.5
],
[
5.4,
1.5
],
[
4.8,
1.6
],
[
4.8,
1.4
],
[
4.3,
1.1
],
[
5.8,
1.2
],
[
5.7,
1.5
],
[
5.4,
1.3
],
[
5.1,
1.4
],
[
5.7,
1.7
],
[
5.1,
1.5
],
[
5.4,
1.7
],
[
5.1,
1.5
],
[
4.6,
1
],
[
5.1,
1.7
],
[
4.8,
1.9
],
[
5,
1.6
],
[
5,
1.6
],
[
5.2,
1.5
],
[
5.2,
1.4
],
[
4.7,
1.6
],
[
4.8,
1.6
],
[
5.4,
1.5
],
[
5.2,
1.5
],
[
5.5,
1.4
],
[
4.9,
1.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5.5
],
[
7.7,
6.7
],
[
7.7,
6.9
],
[
6,
5
],
[
6.9,
5.7
],
[
5.6,
4.9
],
[
7.7,
6.7
],
[
6.3,
4.9
],
[
6.7,
5.7
],
[
7.2,
6
],
[
6.2,
4.8
],
[
6.1,
4.9
],
[
6.4,
5.6
],
[
7.2,
5.8
],
[
7.4,
6.1
],
[
7.9,
6.4
],
[
6.4,
5.6
],
[
6.3,
5.1
],
[
6.1,
5.6
],
[
7.7,
6.1
],
[
6.3,
5.6
],
[
6.4,
5.5
],
[
6,
4.8
],
[
6.9,
5.4
],
[
6.7,
5.6
],
[
6.9,
5.1
],
[
5.8,
5.1
],
[
6.8,
5.9
],
[
6.7,
5.7
],
[
6.7,
5.2
],
[
6.3,
5
],
[
6.5,
5.2
],
[
6.2,
5.4
],
[
5.9,
5.1
]
];
data.addColumn('number','Sepal.Length');
data.addColumn('number','Petal.Length');
data.addRows(datajson);
return(data);
}
// jsDrawChart
function drawChartScatterChartID116e13813ab4() {
var data = gvisDataScatterChartID116e13813ab4();
var options = {};
options["allowHtml"] = [true];
options["title"] = ["Flower Characteristics in Iris"];
var chart = new google.visualization.ScatterChart(
document.getElementById('ScatterChartID116e13813ab4')
);
chart.draw(data,options);
}
// jsDisplayChart
(function() {
var pkgs = window.__gvisPackages = window.__gvisPackages || [];
var callbacks = window.__gvisCallbacks = window.__gvisCallbacks || [];
var chartid = "corechart";
// Manually see if chartid is in pkgs (not all browsers support Array.indexOf)
var i, newPackage = true;
for (i = 0; newPackage && i < pkgs.length; i++) {
if (pkgs[i] === chartid)
newPackage = false;
}
if (newPackage)
pkgs.push(chartid);
// Add the drawChart function to the global list of callbacks
callbacks.push(drawChartScatterChartID116e13813ab4);
})();
function displayChartScatterChartID116e13813ab4() {
var pkgs = window.__gvisPackages = window.__gvisPackages || [];
var callbacks = window.__gvisCallbacks = window.__gvisCallbacks || [];
window.clearTimeout(window.__gvisLoad);
// The timeout is set to 100 because otherwise the container div we are
// targeting might not be part of the document yet
window.__gvisLoad = setTimeout(function() {
var pkgCount = pkgs.length;
google.load("visualization", "1", { packages:pkgs, callback: function() {
if (pkgCount != pkgs.length) {
// Race condition where another setTimeout call snuck in after us; if
// that call added a package, we must not shift its callback
return;
}
while (callbacks.length > 0)
callbacks.shift()();
} });
}, 100);
}
// jsFooter
</script>
<script type="text/javascript" src="https://www.google.com/jsapi?callback=displayChartScatterChartID116e13813ab4"></script>
http://rcharts.io/
library(rCharts)
names(iris) = gsub("\\.", "", names(iris))
rPlot(PetalLength ~ SepalLength , data = iris, color = 'Species', type = 'point')
## Error in myChart$copy(): could not find function "new"
https://plot.ly/r/
library(plotly)
data(iris)
plot_ly(iris, x = Sepal.Length, y = Petal.Length, color = Species, mode = "markers") %>%
layout(title = "Flower Characteristics in Iris")
## Error in file(con, "rb"): cannot open the connection
https://plot.ly/ggplot2/
p <- ggplot(iris) +
geom_point(aes(x=Sepal.Length, y=Petal.Length, color = Species)) +
labs(title = "Flower Characteristics in Iris")
ggplotly(p)
## Error in file(con, "rb"): cannot open the connection