并行坐标在rCharts中绘制,如何重现此图表?

时间:2014-05-08 22:05:02

标签: r data-visualization rcharts

我正在尝试重现页面上的代码:http://rcharts.io/parcoords/

cars <- read.csv('data/cars.csv')
p1 <- rCharts$new()
p1$field('lib', 'parcoords')
p1$set(padding = list(top = 24, left = 0, bottom = 12, right = 200))
p1$set(data = toJSONArray(cars, json = F), 
  colorby = 'economy', 
  range = range(cars$economy),
  colors = c('steelblue', 'brown')
)
p1$print('chart')

下载数据集zip球,解压缩,更改目录和执行上述代码后,我得到的只是

<div id = 'chart' class = 'rChart parcoords'></div>
/layouts/chart.html

我在这里做错了吗?

这应该是结果:

enter image description here

1 个答案:

答案 0 :(得分:3)

该回购中的代码有点过时了。这是一个可用于重现绘图的修改版本。要将parcoords库用于更多绘图,只需将其放在可以轻松访问的文件夹中,并确保setLib方法正确链接到它。

library(downloader)
tf <- tempfile(fileext = ".zip")
download(
  url = "https://github.com/rcharts/parcoords/archive/gh-pages.zip",
  tf
)

# unzip to tempdir and set as working directory
td <- tempdir()
unzip(tf, exdir = td)
setwd(file.path(td, "parcoords-gh-pages"))

# read data
cars <- read.csv('data/cars.csv')

# initialize chart and set path to parcoords library
p1 <- rCharts$new()
p1$setLib("libraries/widgets/parcoords")

# add more details to the plot
p1$set(
  padding = list(top = 24, left = 0, bottom = 12, right = 200)
)
p1$set(
  data = toJSONArray(cars, json = F), 
  colorby = 'economy', 
  range = range(cars$economy),
  colors = c('steelblue', 'brown')
)
p1