rCharts安装及可视化文件保存

rCharts是一个专门用来在R中绘制交互式图形的第三方包,为我们使用R进行可视化展示提供了更多的选择。
rCharts包目前并没有收录进CRAN,而是托管在GitHub上
安装:
使用devtools包进行rCharts包的安装

install.packages(“devtools”)
library(devtools)
install_github(‘ramnathv/rCharts’)

示例:

library('rCharts')
haireye=as.data.frame(HairEyeColor)
head(haireye)
   Hair   Eye  Sex Freq
1 Black Brown Male   32
2 Brown Brown Male   53
3   Red Brown Male   10
4 Blond Brown Male    3
5 Black  Blue Male   11
6 Brown  Blue Male   50
nPlot(Freq~Hair,group='Eye',type='multiBarChart',data=subset(haireye,Sex=='Male'))
x1<nPlot(Freq~Hair,group='Eye',type='multiBarChart',data=subset(haireye,Sex=='Male'))
x1$save('a.html',cdn=TRUE)
cat('<iframe src="x1.html"width=100%></iframe>')

在这里插入图片描述
保存的x1.html:

<!doctype HTML>
<meta charset = 'utf-8'>
<html>
  <head>
    <link rel='stylesheet' href='//tenxer.github.io/xcharts/css/master.css'>
    
    <script src='//d3js.org/d3.v2.min.js' type='text/javascript'></script>
    <script src='//tenxer.github.io/xcharts/js/xcharts.min.js' type='text/javascript'></script>
    
    <style>
    .rChart {
      display: block;
      margin-left: auto; 
      margin-right: auto;
      width: 700px;
      height: 500px;
    }  
    </style>
    
  </head>
  <body >
    
    <figure id = 'chart3e68130014e0' class = 'rChart xcharts'></figure>    
    <script type='text/javascript'>
    var data = {
 "dom": "chart3e68130014e0",
"width":    700,
"height":    500,
"xScale": "ordinal",
"yScale": "linear",
"main": [
 {
 "data": [
 {
 "x": "Black",
"y":     32 
},
{
 "x": "Brown",
"y":     53 
},
{
 "x": "Red",
"y":     10 
},
{
 "x": "Blond",
"y":      3 
} 
] 
},
{
 "data": [
 {
 "x": "Black",
"y":     11 
},
{
 "x": "Brown",
"y":     50 
},
{
 "x": "Red",
"y":     10 
},
{
 "x": "Blond",
"y":     30 
} 
] 
},
{
 "data": [
 {
 "x": "Black",
"y":     10 
},
{
 "x": "Brown",
"y":     25 
},
{
 "x": "Red",
"y":      7 
},
{
 "x": "Blond",
"y":      5 
} 
] 
},
{
 "data": [
 {
 "x": "Black",
"y":      3 
},
{
 "x": "Brown",
"y":     15 
},
{
 "x": "Red",
"y":      7 
},
{
 "x": "Blond",
"y":      8 
} 
] 
} 
],
"id": "chart3e68130014e0" 
},
      chartType = "bar",
      myChart = new xChart(chartType, data, '#chart3e68130014e0');
</script>
<style>figure.rChart {height: 400px;}</style>
    
    <script></script>    
  </body>
</html>

注:html文件在浏览器打开并不能看到效果,缺少js文件!!!

法1:该目录位置存在临时文件,可以获取所需js文件
在这里插入图片描述
法2:官网对应类型目录下可以获取所需js文件(比如此处的xcharts)
在这里插入图片描述

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值