Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R:具有条件颜色的极坐标图_R_Highcharts_Shiny_R Highcharter - Fatal编程技术网

R:具有条件颜色的极坐标图

R:具有条件颜色的极坐标图,r,highcharts,shiny,r-highcharter,R,Highcharts,Shiny,R Highcharter,我正在使用Highcharter的极坐标图,我想知道它是否能够根据标准改变颜色。我用这个图表来比较预算和支出。当支出低于预算时,我希望列为绿色。当支出>预算时,我希望列为红色。这可能吗 例如,代码中的示例:“物流”和“IT&电信”支出将为绿色,所有其他支出类别将为红色 答案必须是动态的,因为计划的结束或结束将不断变化 下面是代码的简化版本 library (shiny) library (highcharter) hc <- highchart() %>% hc_chart(

我正在使用Highcharter的极坐标图,我想知道它是否能够根据标准改变颜色。我用这个图表来比较预算和支出。当支出低于预算时,我希望列为绿色。当支出>预算时,我希望列为红色。这可能吗

例如,代码中的示例:“物流”和“IT&电信”支出将为绿色,所有其他支出类别将为红色

答案必须是动态的,因为计划的结束或结束将不断变化

下面是代码的简化版本

library (shiny)
library (highcharter)

hc <- highchart() %>% 
  hc_chart(polar = TRUE) %>% 
  hc_title(text = "Budget vs Spending") %>% 
  hc_xAxis(categories = c("Energy", "Facilties", "IT & Telecom",
                          "Logistics", "Office Products", "Plant Consumables",
                          "Temp Labor", "Travel", "Other"),
           tickmarkPlacement = "on",
           lineWidth = 0) %>% 
  hc_yAxis(gridLineInterpolation = "polygon",
           lineWidth = 0,
           min = 0) %>% 
  hc_series(
    list(
      name = "Spend",
      data = c(50000, 39000, 42000, 31000, 26000, 14000, 26000, 26000, 26000),
      pointPlacement = "on",
      type = "column"
    ),
    list(
      name = "Budget",
      data = c(43000, 19000, 60000, 35000, 17000, 10000,10000,10000,10000),
      pointPlacement = "on",
      type = "line"
    )
  )

hc
库(闪亮)
图书馆(高级特许)
hc%
hc_图表(极坐标=真)%>%
hc_标题(text=“预算vs支出”)%>%
hc_xAxis(类别=c(“能源”、“设施”、“IT和电信”),
“物流”、“办公产品”、“工厂耗材”,
“临时工”、“差旅”、“其他”),
tickmarkPlacement=“on”,
线宽=0)%>%
hc_yAxis(gridLineInterpolation=“polygon”,
线宽=0,
最小值=0)%>%
hc_系列(
名单(
name=“花费”,
数据=c(50000、39000、42000、31000、26000、14000、26000、26000、26000、26000),
pointPlacement=“on”,
type=“列”
),
名单(
name=“预算”,
数据=c(43000、19000、60000、35000、17000、10000100001000010000),
pointPlacement=“on”,
type=“行”
)
)
hc

您想将
colorByPoint
设置为
TRUE
,然后使用
ifelse
设置
颜色,如下所示:

library(shiny)
library(highcharter)
library(tidyverse)
hc <- highchart() %>% 
  hc_chart(polar = TRUE) %>% 
  hc_title(text = "Budget vs Spending") %>% 
  hc_xAxis(categories = c("Energy", "Facilties", "IT & Telecom",
                          "Logistics", "Office Products", "Plant Consumables",
                          "Temp Labor", "Travel", "Other"),
           tickmarkPlacement = "on",
           lineWidth = 0) %>% 
  hc_yAxis(gridLineInterpolation = "polygon",
           lineWidth = 0,
           min = 0) %>% 
  hc_series(
    list(
      name = "Spend",
      data = c(50000, 39000, 42000, 31000, 26000, 14000, 26000, 26000, 26000),
      pointPlacement = "on",
      colorByPoint = TRUE,
      type = "column",
      colors = ifelse(c(50000, 39000, 42000, 31000, 26000, 14000, 26000, 26000, 26000) > c(43000, 19000, 60000, 35000, 17000, 10000,10000,10000,10000),"#F00","#0F0")
    ),
    list(
      name = "Budget",
      data = c(43000, 19000, 60000, 35000, 17000, 10000,10000,10000,10000),
      pointPlacement = "on",
      type = "line"
    )
  )

hc
库(闪亮)
图书馆(高级特许)
图书馆(tidyverse)
hc%
hc_图表(极坐标=真)%>%
hc_标题(text=“预算vs支出”)%>%
hc_xAxis(类别=c(“能源”、“设施”、“IT和电信”),
“物流”、“办公产品”、“工厂耗材”,
“临时工”、“差旅”、“其他”),
tickmarkPlacement=“on”,
线宽=0)%>%
hc_yAxis(gridLineInterpolation=“polygon”,
线宽=0,
最小值=0)%>%
hc_系列(
名单(
name=“花费”,
数据=c(50000、39000、42000、31000、26000、14000、26000、26000、26000、26000),
pointPlacement=“on”,
colorByPoint=TRUE,
type=“column”,
颜色=ifelse(c(50000、39000、42000、31000、26000、14000、26000、26000、26000)>c(43000、19000、60000、35000、17000、10000100001000010000),“#F00”和“#0F0”)
),
名单(
name=“预算”,
数据=c(43000、19000、60000、35000、17000、10000100001000010000),
pointPlacement=“on”,
type=“行”
)
)
hc

希望这有帮助

我对R不太了解,但在Highcharts JS中,我将负责更新的代码放在
chart.events.render
属性中:我使用
redrawEnabled
标志来防止在该事件中重新绘制图表所导致的无限递归循环(
render
调用
redraw
事件本身)。