在rmarkdown中切换dygraph的logscale选项

时间:2017-12-08 01:54:06

标签: javascript r markdown knitr dygraphs

我真的很喜欢带有复选框的dygraph来切换Y轴到logscale。我知道我可以用闪亮的方式做到这一点,但是我可以使用没有光泽的rmarkdown来完成我为此项目所需的所有其他内容,这使我能够在不必设置闪亮服务器的情况下提供.html。

我知道事情的dygraph方面并不复杂 http://dygraphs.com/options.html#logscale

我认为rmarkdown当然足够灵活 http://livefreeordichotomize.com/2017/01/24/custom-javascript-visualizations-in-rmarkdown/

但是怎么样?

1 个答案:

答案 0 :(得分:1)

您可以使用{.tabset}并分别绘制两个比例。

---
output:
  html_document:
    code_folding: hide
    theme: flatly
    toc: yes
    toc_depth: 3
    toc_float: yes
---

```{r setup, include=FALSE}
library(tidyr)
library(dplyr)
library(tibble)
library(dygraphs)
```


# Plots {.tabset .tabset-fade .tabset-pills}


## Normal Y

```{r plot_norm}
dygraph(AirPassengers, main = "Airline Passengers / Month") %>%
  dyAxis("x", drawGrid = FALSE) %>%
  dyAxis("y", label = "Passengers (Thousands)") %>%
  dyOptions(includeZero = TRUE, 
            axisLineColor = "navy", 
            gridLineColor = "lightblue")
```


## Log Y

```{r plot_log}
dygraph(AirPassengers, main = "Airline Passengers / Month") %>%
  dyAxis("x", drawGrid = FALSE) %>%
  dyAxis("y", label = "Passengers (Thousands)", logscale = TRUE) %>%
  dyOptions(logscale = TRUE,
            axisLineColor = "navy", 
            gridLineColor = "lightblue")
```