1

I want to set different colors for every point in rPlot. I expected it was rPlot(V2~V1, data=data, type="point", color=color) where color is a vector like c("#6B7BFDFF", "#A7E7BFFF", "#13A0BBFF", ...) but this doesn't work. So what is the correct grammar? Thank you.

By the way can I find the documentation of rCharts somewhere? I only see examples on the project's website.

Ziyuan
  • 4,215
  • 6
  • 48
  • 77

1 Answers1

2

Documentation is still a work in progress but closer than ever. If you choose to go with polycharts (make sure you are aware of paid commercial licensing), then these examples might be helpful. Here is another StackOverflow question on the same topic. I made a quick example below.

    library(rCharts)


    data(iris)
    colnames(iris) <- sapply(colnames(iris), FUN = gsub, pattern = "\\.", replacement = "")
    p5 <- rPlot(SepalWidth ~ SepalLength, data = iris, color = "Species", type = "point", height = 400)
    # again match polychartjs example exactly to show how we can change axis and legend titles
    p5$guides(color = list(scale = "#! function(value){
      color_mapping = {versicolor: '#ff2385',setosa:'#229922',virginica:'#2B24D6'}
      return color_mapping[value];                  
    } !#"), y = list(title = "sepalWidth"), x = list(title = "sepalLength"))
    p5$set(title = "Iris Flowers")
    p5

If you choose to use another library, specifying the color will be different, so let me know and I'll be glad to help out.

Community
  • 1
  • 1
timelyportfolio
  • 6,479
  • 30
  • 33
  • Thank you. I read that question and the answer before. But in that question it's about remapping some default colors coming from the grouping (like `Species`). But I want to give different colors for different points (so I have roughly 1000 elements in the color vector). I think my case is different and that's why I asked. When I mention the documentation, I mean, for example, I don't know how to use the `p$guides` or `p$set` as you do. – Ziyuan Sep 19 '14 at 05:05
  • do you want to specify a unique color for each point? are you trying to do a gradient? – timelyportfolio Sep 19 '14 at 13:39
  • main issue with documentation is I can't find how to do in `polycharts`. If you know how to do in `polycharts`, then it is fairly easy to translate. – timelyportfolio Sep 19 '14 at 13:48
  • I am not bound to `polycharts` so if it can be done with other libraries like `nvd3` I'll be fine with it. – Ziyuan Sep 19 '14 at 18:03
  • I am doing dimensional reduction to a 2-sphere (from 3D to 2D) so I want to use color to indicate the original coordinates, the idea is similar to the figure 2 of [this paper](http://jmlr.org/papers/volume11/venna10a/venna10a.pdf). – Ziyuan Sep 19 '14 at 18:45