highcharter R语言

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

ValuesA highcharter chartDownloads201220132014201520160k2.5k5k7.5k10k12.5k

2、总函数hchart

#highcharter可以通过hchart绘制各种对象并添加主题
data(diamonds, package = "ggplot2")
hchart(diamonds$price, color = "#B71C1C", name = "Price") %>%
  hc_title(text = "You can zoom me")

ValuesYou can zoom mePrice2k4k6k8k10k12k14k16k18k0k1k2k3k4k5k6k

hchart(diamonds$cut, colorByPoint = T, name = "Cut") %>%
  hc_title(text = "Aijun")

ValuesAijunCutFairGoodVery GoodPremiumIdeal0k5k10k15k20k25k

#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())

ValuesCharting Example using hchartSeriesARIMA(0,1,1)(0,1,0)[12]level 80level 9519501952195419561958196019620100200300400500600700800900

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()) 

Zoom1m3m6mYTD1yAllFromJan 12, 2015ToMay 24, 2016E2E1Charting some SymbolsData extracted using quantmod packageMar '15May '15Jul '15Sep '15Nov '15Jan '16Mar '16May '16May '15Sep '15Jan '16May '16100120140160180

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) 

060US Counties unemployment rates, April 2015+-0% - 2%2% - 4%4% - 6%6% - 8%8% - 10%10% - 50%● Series 1Lucas: 5
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值