如何旋转dygraph x标签

时间:2016-01-30 17:16:03

标签: r dygraphs

使用dygraphs我希望能够旋转x轴标签。 vignette没有告诉它。

在下面的示例中,我希望将日期旋转为垂直显示

enter image description here

1 个答案:

答案 0 :(得分:2)

你可以试试

首先将此css(作为dygraph.css)文件保存在工作目录中。您可以使用css文件,但是您必须以某种方式调整绘图大小,因为我们几乎看不到x轴标签。您可以增加字体大小,但标签的一半会被切断。

.dygraph-title {
  color: navy;
  font-weight: bold;
}
.dygraph-axis-label-x {
-webkit-transform: rotate(-90deg); 
-moz-transform: rotate(-90deg);
    float: right;
    margin: 0 0 10px 10px;
      font-size: 5px;
}
img.resize{
    width:540px; /* you can use % */
    height: 250;
}
graph_div {
  position: absolute;
  left: 20px;
  right: 20px;
  top: 140px;
  bottom: 300px;
}

然后使用你的例子

lungDeaths <- cbind(ldeaths, mdeaths, fdeaths)
dygraph(lungDeaths, main = "Deaths from Lung Disease (UK)") %>%
  dyOptions(colors = RColorBrewer::brewer.pal(3, "Set2")) %>% dyCSS("dygraph.css")

给出: enter image description here