Highcharter
junjun
2016年5月25日
参考:http://jkunst.com/highcharter/highcharts-api.html
1、示例
#1、Hello World Example
#install.packages("purrr")
#install.packages("highcharter")
library(highcharter)
hc <- highchart() %>%
hc_chart(type="column") %>%
hc_title(text="A highcharter chart") %>%
hc_xAxis(categories=2012:2016) %>%
hc_add_series(data = c(3900, 4200, 5700, 8500, 11900), name = "Downloads")
hc
2、总函数hchart
#highcharter可以通过hchart绘制各种对象并添加主题
data(diamonds, package = "ggplot2")
hchart(diamonds$price, color = "#B71C1C", name = "Price") %>%
hc_title(text = "You can zoom me")
hchart(diamonds$cut, colorByPoint = T, name = "Cut") %>%
hc_title(text = "Aijun")
#hchart类可以画的最漂亮的是forecast预测对象
library(forecast)
## Loading required package: zoo
##
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
## Loading required package: timeDate
## This is forecast 6.2
airforecast <- forecast(auto.arima(AirPassengers), lelel=95)
hchart(airforecast) %>%
hc_title(text = "Charting Example using hchart") %>%
hc_add_theme(hc_theme_smpl())
highstock
#highstock画金融时间序列
library(quantmod)
## Loading required package: xts
## Loading required package: TTR
## Version 0.4-0 included new data defaults. See ?getSymbols.
usdjpy <- getSymbols("USD/JPY", src="oanda", auto.assign = F)
## As of 0.4-0, 'getSymbols' uses env=parent.frame() and
## auto.assign=TRUE by default.
##
## This behavior will be phased out in 0.5-0 when the call will
## default to use auto.assign=FALSE. getOption("getSymbols.env") and
## getOptions("getSymbols.auto.assign") are now checked for alternate defaults
##
## This message is shown once per session and may be disabled by setting
## options("getSymbols.warning4.0"=FALSE). See ?getSymbols for more details.
eurkpw <- getSymbols("EUR/KPW", src="oanda", auto.assign = F)
dates <- as.Date(c("2015-05-08", "2015-09-12"), format = "%Y-%m-%d")
highchart(type = "stock") %>%
hc_title(text = "Charting some Symbols") %>%
hc_subtitle(text = "Data extracted using quantmod package") %>%
hc_add_series_xts(usdjpy, id = "usdjpy") %>%
hc_add_series_xts(eurkpw, id = "eurkpw") %>%
hc_add_series_flags(dates,
title = c("E1", "E2"),
text = c("Event 1", "Event 2"),
id = "usdjpy") %>%
hc_add_theme(hc_theme_flat())
highmaps
#使用热力图可以绘制地图和等线图
#install.packages("viridisLite")
library("viridisLite")
library("dplyr")
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:xts':
##
## first, last
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
data(unemployment)
data(uscountygeojson)
dclass <- data_frame(from = seq(0, 10, by = 2),
to = c(seq(2, 10, by = 2), 50),
color = substring(viridis(length(from), option = "C"), 0, 7))
dclass <- list.parse3(dclass)
highchart() %>%
hc_title(text = "US Counties unemployment rates, April 2015") %>%
hc_add_series_map(uscountygeojson, unemployment,
value = "value", joinBy = "code") %>%
hc_colorAxis(dataClasses = dclass) %>%
hc_legend(layout = "vertical", align = "right",
floating = TRUE, valueDecimals = 0,
valueSuffix = "%") %>%
hc_mapNavigation(enabled = TRUE)