Error while plotting data in rchart using HighChar

2019-07-31 23:03发布

I am reading data from file and plotting data using rchart/highchart but i am getting following Error.

sampledata

A   B   C
2   3   0
4   5   0
4   -3   1
-8   5   1
2   -3   2
-2   -5   2
12   3   3
-4   5   3

R Scitpt:

require(devtools)
install_github(’rCharts’ ,’ramnathv’)
sampledata<-read.csv("data.csv",header=TRUE,sep="\t")
h1 <- hPlot(x = sampledata[1,], y = sampledata[2,], data = sampledata, type = "scatter", group=sampledata[3,])

Error in .subset2(x, i, exact = exact) : invalid subscript type 'list'

How can i plot scatter plot using rcharts by calling Highcharts internally?

1条回答
迷人小祖宗
2楼-- · 2019-07-31 23:41

Assuming your column names in the sampledata are A, B and C, this should work:

h1 <- hPlot(x = 'A', y = 'B', data = sampledata, type = "scatter", group='C') 

Function hPlot does not want to get the actual data values. Instead, you should give as an input the names of columns you want to plot. Alternatively, you can also use a formula interface. For example, see, https://github.com/ramnathv/rCharts/blob/master/inst/libraries/highcharts/examples.R.

查看更多
登录 后发表回答