pfu*_*ert 7 r bar-chart dygraphs
有没有办法在Dygraphs网站本身http://dgraphs.com/tests/plotters.html上使用R中的dygraphs的不同类型的情节?使用R时有没有办法访问这些?从R网站的dygraph中获取的一个简单示例如下:
library(dygraphs)
library(dplyr)
lungDeaths <- cbind(mdeaths, fdeaths)
dygraph(lungDeaths)
# How to choose a different type of plot?
Run Code Online (Sandbox Code Playgroud)
/编辑.所以我发现你可以在这里使用带有dygraphs的自定义绘图仪:http://blog.dygraphs.com/2012/08/introducing-custom-plotters.html .有没有办法在R中得到它?
我在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);
}
}")
Run Code Online (Sandbox Code Playgroud)