R语言之数据可视化---交互式图表recharts

环图

REmap包的github链接地址:https://github.com/taiyun/recharts
几个样例demo:http://xwj.565tech.com/jianshu/recharts/ring.html
http://xwj.565tech.com/jianshu/recharts/dashboard.html
http://xwj.565tech.com/jianshu/recharts/bubble.html

一.安装方式:

if (!require(devtools)) library(devtools)
install_github("madlogos/recharts")

二.使用方法:

1.散点图/气泡图

echartr(iris, x=SepalWidth, y=PetalWidth)
多个维度:series控制
echartr(iris, x=SepalWidth, y=PetalWidth, series=Species)

气泡图:type:标签控制

> echartr(iris, SepalWidth, PetalWidth,series = Species, weight=PetalLength, type='bubble')


sandian.png

ECharts.png

ECharts(1).png

2.管道操作

echartr(iris, SepalWidth, PetalWidth, weight=PetalLength) %>%
    setDataRange(calculable=TRUE, splitNumber=0, labels=c('Big','Small'),
                 color=c('red', 'yellow', 'green'), valueRange=c(0, 2.5))


ECharts(2).png

3.折线图

先改造下内置数据集:
aq <- airquality
aq$Date <- as.Date(paste('1973', aq$Month, aq$Day, sep='-'))
aq$Day <- as.character(aq$Day)
aq$Month <- factor(aq$Month, labels=c("May", "Jun", "Jul", "Aug", "Sep"))

echartr(aq, Date, Temp, type='line') %>%
    setTitle('NY Temperature May - Sep 1973') %>% setSymbols('none')

含有分类属性:
echartr(aq, Day, Temp, Month, type='line') %>%
    setTitle('NY Temperature May - Sep 1973, by Month') %>% 
    setSymbols('emptycircle')

带有时间轴(带有动态效果哦~~~):
echartr(aq, Day, Temp, t=Month, type='line') %>%
    setTitle('NY Temperature May - Sep 1973, by Month') %>% 
    setSymbols('emptycircle')

也可画面积图:type属性控制
echartr(aq, Day, Temp, Month, type='area', subtype='stack') %>%
    setTitle('NY Temperature May - Sep 1973, by Month') %>% 
    setSymbols('emptycircle')




NY Temperature May - Sep 1973.png

NY Temperature May - Sep 1973, by Month.png

NY Temperature May - Sep 1973, by Month (Month_ Jul).png

NY Temperature May - Sep 1973, by Month(1).png

4.饼图

重构内置数据集
titanic <- data.table::melt(apply(Titanic, c(1,4), sum))
names(titanic) <- c('Class', 'Survived', 'Count')
knitr::kable(titanic)
画饼图,可以和漏斗图切换
echartr(titanic, Class, Count, type='pie') %>%
    setTitle('Titanic: N by Cabin Class')

多个饼图:
echartr(titanic, Survived, Count, facet=Class, type='pie') %>%
    setTitle('Titanic: Survival Outcome by Cabin Class')

环图:
echartr(titanic, Survived, Count, facet=Class, type='ring') %>%
    setTitle('Titanic: Survival Outcome by Cabin Class')

信息图样环图:
ds <- data.frame(q=c('68% feel good', '29% feel bad', '3% have no feelings'),
              a=c(68, 29, 3))
g <- echartr(ds, q, a, type='ring', subtype='info') %>% 
    setTheme('macarons', width=800, height=600) %>%
    setTitle('How do you feel?','ring_info', 
             pos=c('center','center', 'horizontal'))
g

南丁格尔玫瑰图:
echartr(titanic, Class, Count, facet=Survived, type='rose', subtype='radius') %>% 
    setTitle('Titanic: Survival Outcome by Cabin Class') 
Titanic_ N by Cabin Class.png

Titanic_ N by Cabin Class(1).png

Titanic_ Survival Outcome by Cabin Class.png

Titanic_ Survival Outcome by Cabin Class(1).png

How do you feel_.png

Titanic_ Survival Outcome by Cabin Class(2).png

5.雷达图:

重构内置数据集
cars = mtcars[c('Merc 450SE','Merc 450SL','Merc 450SLC'),
              c('mpg','disp','hp','qsec','wt','drat')]
cars$model <- rownames(cars)
cars <- data.table::melt(cars, id.vars='model')
names(cars) <- c('model', 'indicator', 'Parameter')
knitr::kable(cars)

单个雷达图
echartr(cars, indicator, Parameter, model, type='radar', sub='fill') %>%
    setTitle('Merc 450SE  vs  450SL  vs  450SLC')

多个雷达图:
echartr(cars, indicator, Parameter, facet=model, type='radar') %>%
        setTitle('Merc 450SE  vs  450SL  vs  450SLC')

Merc 450SE vs 450SL vs 450SLC.png

Merc 450SE vs 450SL vs 450SLC(1).png

6.比较有趣的dashboard

构造一个数据集:
data = data.frame(x=rep(c('KR/min', 'Kph'), 2), y=c(3.3, 56, 9.5, 88), 
                  z=c(rep('t1', 2), rep('t2', 2)))
knitr::kable(data)

echartr(data, x, y, type='gauge')
多个dashboard:
echartr(data, x, y, facet=x, type='gauge')
带时间轴:
echartr(data, x, y, facet=x, t=z, type='gauge')

ECharts(3).png

ECharts(4).png

ECharts(5).png

基本上常用的数据图表展示recharts都可以很方便和很酷炫的展示,作者只是挑选了几个比较常用的图表类型做了抛砖迎玉,具体的细节各位可以去查看具体的文档:https://madlogos.github.io/recharts/index_cn.html#-en

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • **2014真题Directions:Read the following text. Choose the be...
    又是夜半惊坐起阅读 9,889评论 0 23
  • 鹏澍 | 2014.10.09 偌大的北京城,却是一个人喝酒,一个人坐地铁,一个人吃饭,一个人走着熟悉的街道,留下...
    鹏澍阅读 563评论 0 50
  • 李斯功也昭昭,过也煌煌。前半身雄才大展,后半身似欲做怂。最后终于陷于万劫不复之境地。不仅后期被赵高玩弄于鼓掌,而且...
    蕞亻阅读 427评论 0 0