0

I try this:

testd <- data.frame(ID=1:10,cl=sample(1:10,100,replace=TRUE),x=runif(100),y=2*runif(100))
testd$ID <- factor(testd$ID)
testd$cl <- factor(testd$cl)
levels(testd$cl)
rPlot(y~x, data = testd, color = 'cl', 
      tooltip = "#!function(item){ return 'cl: ' + item.cl + ' id: ' + item.ID }!#",
      type = 'point', ylim=c(-0.5,1.5))

But I get a legend with only 4 levels (2,4,6,8), while I have 10 levels in cl Why? Also, I do not get to control the axes limits.

Any help appreciated,

Thanks

user2955884
  • 405
  • 2
  • 11
  • I think you may want `cl=rep(1:10,10)` instead of using `sample`. `sample` will randomly pick values in `1:10`, it doesn't have to take all of them (and therefore not all colors appear). – Vincent May 22 '14 at 12:58
  • Vincent,sample(1:10,100,replace=TRUE) is correct, I just create 100 integers between 1 and 10 with repetition. Note levels(testd$cl) correctly prints the 10 labels. I do have a typo in ID=1:10 which should be ID=1:100, but this does not have any effect on the colors. Thanks. – user2955884 May 22 '14 at 13:49
  • But you want each cl level to be associated with 1 ID ? – Vincent May 22 '14 at 13:54
  • No. The ID is just to identify the individual (row) in the plot. I check with the tooltip class (cl) and individual (ID). Color refers to cl only. – user2955884 May 22 '14 at 14:07
  • The trouble is that polychart is intepreting `cl` as numeric. I believe this is a bug (or a feature) in polycharts. There is a way to specify the column classes explicitly while loading data in polycharts, but that feature is currently not implemented in rCharts. – Ramnath May 22 '14 at 15:33
  • Therefore no way to get correct colors for categorical variables? no workaround? – user2955884 May 23 '14 at 08:32

0 Answers0