R/MarkDown

[R Markdown] Markdown, DT datatable, dygraph 기본 옵션

슈퍼짱짱 2021. 4. 29. 13:53
반응형

(나를 위한) 평소 고정으로 사용하는 마크다운 옵션들 정리

1. Markdown

 

--- 
title: "[Title]" 
author: "by SK C&C 이다경 선임 - 2021/04/29" 
output:  
  rmdformats::readthedown: 
    code_folding: hide 
    number_sections: TRUE
    toc_depth: 4
--- 


<style> 
#TOC { 
  top: 1%; 
  opacity: 0.5; 
} 
#TOC:hover { 
  opacity: 1; 
} 
</style>

> Description

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo=TRUE, warning=FALSE, message=FALSE, results = 'asis')
options(warn = F, scipen = 100, digits = 3)

# Library
library(tidyverse)
library(ggplot2)
library(gridExtra)
library(knitr)
library(DT)
library(plotly)
library(htmltools)
library(pander)
library(data.table)
library(dygraphs)
library(xts)
library(Metrics)
library(readxl)

old <- theme_set(theme_bw())
panderOptions('round',3)
```

 

2. DT datatable

 

myTable <- function(table){
  datatable(table, 
            rownames = F,
            filter = "bottom", 
            extensions = "Buttons", 
            options = list(dom ='Bfrtip', buttons =c(I('colvis'),'copy','csv', 'excel','print','pdf'), scrollX = T),
            height = "100%", width = "100%")
}

 


 

3. Dygraph

time series 기반 dula y axis 그래프 

myDygraph <- function(data, x, y){
  graph_temp <- data %>% dplyr::select(time, y, x)
  graph_temp <- xts(graph_temp[,-1], order.by = graph_temp$time)
  fig <- dygraph(graph_temp, width = 800) %>%
    dyAxis("y", label = y) %>%
    dyAxis("y2", label = x, independentTicks = TRUE) %>%
    dySeries(y, axis = 'y') %>%
    dySeries(x, axis = 'y2')  %>%
    dyCrosshair(direction = "vertical") %>%
    dyOptions(useDataTimezone = T) %>%
    dyRangeSelector(height = 20, strokeColor = "") %>%
    dyHighlight(highlightCircleSize = 5, 
                highlightSeriesBackgroundAlpha = 0.2,
                hideOnMouseOut = TRUE,
                highlightSeriesOpts = list(strokeWidth = 2)) %>% 
    dyLegend(show = "always")
  return(fig)
}

 

반응형