r语言学习@IT·互联网玩转大数据

R语言之数据可视化---D3可交互图表及流程图

2017-04-27  本文已影响993人  willnight
wordcloud

DiagrammeR包的github链接地址:https://github.com/juba/scatterD3
几个样例demo:http://xwj.565tech.com/jianshu/scatterR/scatter1.html
http://xwj.565tech.com/jianshu/scatterR/scatter2.html
http://xwj.565tech.com/jianshu/scatterR/scatter4.html
http://xwj.565tech.com/jianshu/scatterR/scatter5.html

一.安装方式:

install.packages("scatterD3")

devtools::install_github("juba/scatterD3")

二.使用方法:

使用形式与前面介绍过的图表可视化类似,这个包只是提供了一些d3的效果,能够使你的图表产生缩放和其他一些效果

library(scatterD3)
scatterD3(x = mtcars$wt, y = mtcars$mpg)

##point_size:点的大小,point_opacity:点的透明度
scatterD3(data = mtcars, x = wt, y = mpg, 
          point_size = 175, point_opacity = 0.3, fixed = TRUE,
          colors = "#000")

##hover_size:鼠标放上去后点的放大倍数,
scatterD3(data = mtcars, x = wt, y = mpg, 
          point_size = 100, point_opacity = 0.5,
          hover_size = 6, hover_opacity = 1)

#可以很方便的改变变量名称
mtcars$cyl_fac <- paste(mtcars$cyl, "willnight")
scatterD3(data = mtcars, x = cyl_fac, y = mpg,point_size=60,hover_size = 4)

#给点赋予文字标签

mtcars$names <- rownames(mtcars)
scatterD3(data = mtcars, x = wt, y = mpg, lab = names, labels_size = 15,point_size=60,hover_size = 4)
##利用颜色形状处理分类变量
scatterD3(data = mtcars, x = wt, y = mpg, col_var = cyl, symbol_var = gear)


#lasso属性设置为TRUE后,用户可以自由选取区域中的点
mtcars$names <- rownames(mtcars)
scatterD3(data = mtcars, x = wt, y = mpg, lab = names, lasso = TRUE)
1.png
2.png
3.png
4.png
5.png
6.png

基本操作的话就这些,一些详细的操作的话可以去github上去看一下。作为R语言可视化的最后一篇文章,本篇后部分再为大家粗略介绍一些可视化包。

##griViz函数包裹,里面点(node)很方便可以列举,线(edge)通过箭头指向[ 里可以设置属性值]
grViz("
digraph demo{
node[shape=box
penwidth=2
]
A;B;C;D;E;F
node[shape=circle
1;2;3;4;5;6;7;8

edge[arrowhead=diamond]
A->1;B->2;C->3,D->4;E->5;F->6;
D->8[label='will']

}
      ")

diagrammerR.png
#按着思路写就行,箭头指指就行
DiagrammeR("
sequenceDiagram;
customer->>web:ask Api;
web->>customer:有token么;
customer->>web:token给你;
web->>database:这个用户token匹配么;
alt 如果匹配
database->>web: 匹配的;
web->>database:拿数据;
database->>web:数据给你;
web->>customer:数据给你;
else 不匹配
database->>web:不匹配;
web->>customer:error;
end
           ")
diagrammeR2.png

更多详细用法:http://rich-iannone.github.io/DiagrammeR/

#1.绘制简单的图形很方便,使用内置词频数据
wordcloud2(demoFreq,size = 0.7,shape = 'star')
wordcloud2(demoFreq,size = 0.7,shape = 'cardioid')
#2.绘制自定义的字母或汉字lettercloud,绘制中文字体时不能缺失letterFont属性
letterCloud(demoFreq,word = "X",wordSize = 1)
letterCloud(demoFreq,word = "简",letterFont = "楷体")
#3.可以在图片上绘制词云,但图片要求是有两种色差
wordcloud2(demoFreq,figPath = "/Users/jiang/Desktop/cat.jpg",size = 1)
  
wc-1.png
wc-2.png
wc-3.png
wc-4.png
wordcloud
cat.jpg

作为绘制词云来讲这个包还是非常有意思的,那可视化方面的话暂时先介绍这些,以后如果有其他好玩的可视化包也会分享出来,接下来的主题会进入具体数据分析阶段!!!!

上一篇下一篇

猜你喜欢

热点阅读