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)
基本操作的话就这些,一些详细的操作的话可以去github上去看一下。作为R语言可视化的最后一篇文章,本篇后部分再为大家粗略介绍一些可视化包。
- DiagrammeR包:方便实现流程图
##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']
}
")
#按着思路写就行,箭头指指就行
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
")
更多详细用法:http://rich-iannone.github.io/DiagrammeR/
- wordcloud2包:绘制词云
常用参数:
(1)data:词云生成数据,包含具体词语以及频率;
(2)size:字体大小,默认为1,一般来说该值越小,生成的形状轮廓越明显;
(3)fontFamily:字体,如‘微软雅黑’;
(4)fontWeight:字体粗细,包含‘normal’,‘bold’以及‘600’;;
(5)color:字体颜色,可以选择‘random-dark’以及‘random-light’,其实就是颜色色系;
(6)backgroundColor:背景颜色,支持R语言中的常用颜色,如‘gray’,‘blcak’,但是还支持不了更加具体的颜色选择,如‘gray20’;
(7)minRontatin与maxRontatin:字体旋转角度范围的最小值以及最大值,选定后,字体会在该范围内随机旋转;
(8)rotationRation:字体旋转比例,如设定为1,则全部词语都会发生旋转;
(9)shape:词云形状选择,默认是‘circle’,即圆形。还可以选择‘cardioid’(苹果形或心形),‘star’(星形),‘diamond’(钻石),‘triangle-forward’(三角形),‘triangle’(三角形),‘pentagon’(五边形);
#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)