【问题标题】:rCharts: Change the individual point colors of a time series plot (Highcharts)rCharts:更改时间序列图的各个点颜色(Highcharts)
【发布时间】:2014-10-22 12:20:55
【问题描述】:

我正在尝试使用 rCharts 到 Highcharts 库的绘图接口创建时间序列图。 我试图弄清楚如何根据其 y 值设置单个点的颜色。我找到了一种为线和点设置不同颜色的方法,但只能作为一个组,而不是单独的数据点。

这是测试代码:

library(rCharts)
library(rjson)
TransformDate <- function(x){
  as.numeric(as.POSIXct(x, origin="1970-01-01")) * 1000
}

x <- TransformDate(c('2013-01-01 11:05:35', '2013-03-03 04:50:35', '2013-05-05 21:09:37', '2013-07-07 12:49:05'))
y <- c(1,56,123,1000)

w<-TransformDate(c('2013-01-10 11:05:35', '2013-03-13 04:50:35', '2013-05-15 21:09:37', '2013-07-17 12:49:05'))
z<-c(10, 100, 70, 500)

df1 <- data.frame(x = x,y = y)
df2 <- data.frame(x = w, y = z)
combo <- rCharts:::Highcharts$new()
combo$series(list(list(data = rCharts::toJSONArray2(df1, json = F, names = F), name = "Temp1", marker = list(fillColor = c('#999'), lineWidth=6, lineColor=c('#999'))),
              list(data = rCharts::toJSONArray2(df2, json = F, names = F), name = "Temp2")))


combo$xAxis(type='datetime')
combo$chart(type = "scatter")
combo$chart(zoomType="x")

combo

我相信这可以在 Polycharts 中完成,但我使用 highcharts 的原因是它可以很好地绘制时间序列数据,并且它还具有很酷的放大功能。

提前感谢您的帮助和建议。 一月

【问题讨论】:

    标签: r highcharts rcharts


    【解决方案1】:

    这是分别控制线条/标记的颜色/大小的一种方法:

    h <- rCharts:::Highcharts$new()
    h$series(list(
      list(data = rCharts::toJSONArray2(df1, json = FALSE, names = FALSE), 
          name = "Big Reds",
          color = '#FF0000',
          lineWidth = 4,
          marker = list(
            fillColor = '#FFA500', 
            radius = 10)
          ),
      list(data = rCharts::toJSONArray2(df2, json = FALSE, names = FALSE), 
          name = "Small Blues", 
          color = '#0000FF',
          lineWidth = 2,
          marker = list(
            fillColor = '#ADD8E6',
            radius = 6)
    )))
    h$xAxis(type = 'datetime')
    h$chart(type = "scatter")
    h$chart(zoomType = "x")
    h
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-04-14
      • 1970-01-01
      • 1970-01-01
      • 2016-04-07
      • 1970-01-01
      • 2021-02-11
      • 2014-06-16
      相关资源
      最近更新 更多