在 rmarkdown 中切换 dygraph 的 logscale 选项
Toggle logscale option for dygraph in rmarkdown
我真的很想要一个带有复选框的 dygraph,可以将 Y 轴切换为对数刻度。我知道我可以用 shiny 做到这一点,但我可以使用 rmarkdown 做这个项目所需的几乎所有其他东西而无需 shiny,这让我可以交付 .html 而无需设置 shiny 服务器。
我知道它在 dygraph 方面并不复杂
http://dygraphs.com/options.html#logscale
而且我认为 rmarkdown 确实足够灵活,可以做到这一点
http://livefreeordichotomize.com/2017/01/24/custom-javascript-visualizations-in-rmarkdown/
但是如何呢?
您可以使用 {.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")
```
我真的很想要一个带有复选框的 dygraph,可以将 Y 轴切换为对数刻度。我知道我可以用 shiny 做到这一点,但我可以使用 rmarkdown 做这个项目所需的几乎所有其他东西而无需 shiny,这让我可以交付 .html 而无需设置 shiny 服务器。
我知道它在 dygraph 方面并不复杂 http://dygraphs.com/options.html#logscale
而且我认为 rmarkdown 确实足够灵活,可以做到这一点 http://livefreeordichotomize.com/2017/01/24/custom-javascript-visualizations-in-rmarkdown/
但是如何呢?
您可以使用 {.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")
```