在hplot中添加垂直线和水平线(rcharts) [英] add vertical and horizontal lines in hplot (rcharts)

查看:368
本文介绍了在hplot中添加垂直线和水平线(rcharts)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在reallyjs演示文稿的高图(rcharts)中添加水平线和垂直线. 我试图以此方式修改此帖子的代码:

I'm trying to add horizontal and vertical lines in a highchart (rcharts) in a revealjs presentation. I tried to modify the code of this post in this way:

require(xlsx) 
library(rCharts)

Perhplot.df <-read.xlsx("C:\\RDirectory\\AREALAVORO\\JOB\\RISULTATI2.xlsx", sheetName="completo2")

lDf <- split(Perhplot.df, Perhplot.df$variable)

h16 <- hPlot(protection ~ days, data = lDf$Exposure, 
type = "bubble", 
group = "label",
title = "By Days of Exposure", 
subtitle = "Move the mouse pointer on the bubbles to view the data",
size = "cluster_size", 
group = "label")
h16$set(width = 1000, height = 600)

ord <- c("Less than 1 week"=0,
"1-2 weeks"=1,
"3-4 weeks"=2,
"More than 4 weeks"=3,
"Mean"=4
)
h16$params$series <- lapply(h16$params$series, function(d){
temp = ord[d$name]
names(temp) = NULL
d$legendIndex = temp
return(d)
})
h16$yAxis(min = 35, max = 70, title = list(text = "Level of Protection"))
h16$xAxis(min = 0, max = 45, title = list(text = "Days of Exposure"))

dfy<-data.frame(y=c(35,58,70), x=c(18.8,18.8,18.8))
h16$layer(y~x,data=dfy,type="line",color=list(const = 'darkblue'))

h16$show('inline', include_assets = TRUE)

气泡图还可以,但是随后我尝试添加垂直线,但出现此错误:

the bubble plot is ok but then I try to add the vertical line I have this error:

Error in envRefInferField(x, what, getClass(class(x)), selfEnv) : ‘layer’ is not a valid field or method name for reference class "Highcharts"

因此该解决方案适用于Dimple Charts,但不适用于Highcharts ...

So the solution works for Dimple Charts but not for Highcharts...

推荐答案

rcharts highcharts plotLines .

您需要使用plotLines参数:

You need to use plotLines argument:

library("rCharts")
# Some data
x <- abs(rnorm(10))
# A graph with column
h <- Highcharts$new()
h$chart(type = "column")
h$series(data = x)
h$xAxis(categories = letters[1:10])
# the horizontal line
h$yAxis(title = list(text = "rnorm()"),
    plotLines = list(list(
      value = mean(x),
      color = '#ff0000',
      width = 3,
      zIndex = 4,
      label = list(text = "mean",
                   style = list( color = '#ff0000', fontWeight = 'bold' )
      ))))
h

添加垂直,可以通过xAxis更改yAxis.

Yo add vertical you change yAxis by xAxis.

或者如果您使用 highcharter (这是R的highcharts的新包装):

Or if you use highcharter (It's a new wrapper of highcharts for R):

h2 <- highchart() %>% 
  hc_chart(type = "column") %>% 
  hc_add_serie(data = x) %>% 
  hc_xAxis(categories = letters[1:10]) %>% 
  hc_yAxis(title = list(text = "rnorm()"),
        plotLines = list(list(
          value = mean(x),
          color = '#ff0000',
          width = 3,
          zIndex = 4,
          label = list(text = "mean",
                       style = list( color = '#ff0000', fontWeight = 'bold'   )
          ))))
h2

来源: http://jkunst.com/highcharter/highcharts -api.html#hc_xaxis-and-hc_yaxis

这篇关于在hplot中添加垂直线和水平线(rcharts)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆