## load packages pacman::p_load("pacman", "dplyr", "knitr", "rmarkdown", "rmdformats", "xts", "reshape2", "formattable", "kyoboLT", "ggplot2") ## global option opts_chunk$set(fig.align = "center", warning = F, message = F) # for knitr theme_set(theme_bw() + theme(axis.text.x = element_text(angle = 90))) # for ggplot2 set.seed(1004)
Under Construction
Useful R package for kyobo retirement pension marketing team.
본 패키지는 크게 3가지 성격을 가지고 있습니다.
xdiff_returns()
, mmadjust()
, trim()
등tmplot()
, ky_colors()
, prop_waffle()
, cormat()
등efff()
등tmplot()
시계열 자료가 있을 때 20, 50, 120일 이동평균선과 함께 플랏팅을 해줍니다. 데이터프레임일때 동작하며 단변수일 경우
library("quantmod") data <- getSymbols("^ks11", from=Sys.Date()-1000, to = Sys.Date(), auto.assign = F)[,1] tmplot(data)
다변수일경우 입니다.
data <- getSymbols("^ks11", from=Sys.Date()-1000, to = Sys.Date(), auto.assign = F) tmplot(data)
xdiff_returns()
data(sample_index) sample_index xdiff_returns(sample_index)
efff()
수익률을 기반으로 효율적투자선을 그려줍니다.
이를 이용하여 최적수익률포트폴리오, 목표수익률포트폴리오에 대한 분석이 가능합니다.
returns <- xdiff_returns(sample_index, 1) ef <- efff(returns, rg = 0.01039, rfr = 0.001, plot.only.efff = F) attr(ef, "poolset") %>% head
mmadjust()
최대 최소값을 임의의 값으로 보정시킵니다. 즉 임의값을 초과하는 부분이 보정됩니다.
(x <- c(NA, 1:100*.01, NA)) mmadjust(x, .2, .8)
trim()
정규표현식에 기반한 공백문자에 대한 trimming 을 제공합니다.
trim(" Wow! ", method = "leading") trim(" Wow! ", method = "trailing") " Wow! " %>% trim %>% trim(method = "leading")
ky_colors()
자주사용하는 색에 대한 팔레트함수입니다.
demo.pal <- function(n, border = if (n < 32) "light gray" else NA, main = paste("color palettes; n=", n), ch.col = c("rainbow(n, start=.7, end=.1)", "heat.colors(n)", "terrain.colors(n)", "topo.colors(n)", "cm.colors(n)", "ky_colors(n)")){ nt <- length(ch.col) i <- 1:n; j <- n / nt; d <- j/6; dy <- 2*d plot(i, i+d, type = "n", yaxt = "n", ylab = "", main = main) for(k in 1:nt){ rect(i-.5, (k-1)*j+ dy, i+.4, k*j, col = eval(parse(text = ch.col[k])), border = border) text(2*j, k * j + dy/4, ch.col[k]) } } demo.pal(n = 16)
prop_waffle()
비율에 대한 와플차트를 제공합니다.
x <- c("Apple" = 1, "Banana" = 2, "Watermelon" = 3) prop_waffle(x, 1, 4, size = 1) prop_waffle(x, 1, 4, size = 1, colors = ky_colors(3, random = T), title = "Using ky_colors() Palettes")
cormat()
상관행렬도를 시각화하며 psych::pairs.panels()
에 기반합니다.
cormat(cars)
github 원격저장소에 본 패키지 프로젝트가 담겨 있습니다.
devtools package 의 install_github()
함수를 통해 설치 가능합니다.
아래의 코드를 실행하세요.
devtools::install_github("lovetoken/kyoboLT")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.