library(tidyverse)
library(readxl)
library(lubridate)
# https://blogs.reed.edu/ed-tech/2015/10/creating-nice-tables-using-r-markdown/
library(knitr) #kable
library(highcharter)
This visualization is interactive in the way that the plots are responsive to the movement of the curser, with corresponding information displayed.
Create dataset in Google Sheet, download to the folder as excel document
#filePath <- file.choose()
filePath <- "/Users/apple/Desktop/货币基金/兴银现金添利货币C.xlsx" #
Asset_Currecy_Raw <- read_excel(filePath)
Xue_Asset_Currecy <-
Asset_Currecy_Raw %>%
mutate(Date = ymd(Date))
1.七日年化收益率
我的代码直接可用。你唯一需要根据你自己数据替换的变量是:
1. Dataset name: 位于 data = Xue_Asset_Currecy %>% select(sevenDay_XingYinC)
2. 你要画的,也就是Y轴的量: 位于 data = Xue_Asset_Currecy %>% select(sevenDay_XingYinC)
3. 横坐标: 换成你的时间变量名
位于 hc_xAxis(categories = Xue_Asset_Currecy %>% select(Date) %>% .[[1]] )
highcharter 兴银添利C vs. 兴全添益A vs. 中信保诚E
series = list(
# 兴银添利C
list(
name = '兴银添利C(018092)7天年化收益率',
color = '#008B00',
data = Xue_Asset_Currecy %>% select(sevenDay_XingYinC) %>% .[[1]]
),
# 兴全添益A
list(
name = '兴全添益A(001820)7天年化收益率',
color = '#FFC125',
data = Xue_Asset_Currecy %>% select(sevenDay_XingQuanA) %>% .[[1]]
),
# 中信保诚E
list(
name = '中信保诚E(018299)7天年化收益率',
color = '#63B8FF',
data = Xue_Asset_Currecy %>% select(sevenDay_ZhongXinE) %>% .[[1]]
),
# 余额宝
list(
name = '余额宝7天年化收益率',
color = 'lightblue',
data = Xue_Asset_Currecy %>% select(sevenDay_YuErBao) %>% .[[1]]
)
)
highchart() %>%
hc_add_series_list(series) %>%
hc_xAxis(categories = Xue_Asset_Currecy %>% select(Date) %>% .[[1]] ) %>%
# add a horizontal line: hc_yAxis
hc_yAxis(plotLines = list(
#list(value = 2.3, width = 1, color = 'red'), #预期基准
#list(value = 1.854, width = 3, color = 'lightblue') #余额宝
))