我在dyOptions中使用繪圖儀來創建條形圖。我剛剛從dygraphs博客複製了barChartPlotter函數。 http://blog.dygraphs.com/2012/08/introducing-custom-plotters.html
library(xts)
library(dygraphs)
library(lubridate)
graph_data <- xts(x = c(1,2,3,4), order.by = lubridate::ymd(c("2015-01-01", "2015-02-01", "2015-03-01", "2015-04-01")))
names(graph_data) <- "value"
dygraph(graph_data) %>%
dyOptions(useDataTimezone = TRUE, plotter =
"function barChartPlotter(e) {
var ctx = e.drawingContext;
var points = e.points;
var y_bottom = e.dygraph.toDomYCoord(0); // see http://dygraphs.com/jsdoc/symbols/Dygraph.html#toDomYCoord
// This should really be based on the minimum gap
var bar_width = 2/3 * (points[1].canvasx - points[0].canvasx);
ctx.fillStyle = e.color;
// Do the actual plotting.
for (var i = 0; i < points.length; i++) {
var p = points[i];
var center_x = p.canvasx; // center of the bar
ctx.fillRect(center_x - bar_width/2, p.canvasy,
bar_width, y_bottom - p.canvasy);
ctx.strokeRect(center_x - bar_width/2, p.canvasy,
bar_width, y_bottom - p.canvasy);
}
}")
嘗試'ggplot2'包。 –
我知道ggplot2,但我想在HTML文件中以交互方式使用它。同步功能對我來說非常有吸引力!我想有一個由這樣的dygraphs提供的範圍選擇器:http://rstudio.github.io/dygraphs/gallery-range-selector.html – pfuhlert