首先,我可能错误地处理了这个任务。 我对diagrammeR功能还很陌生,如果我对diagrammeR的理解是错误的,从编程角度来看,我也不会感到惊讶。
问题出现在代码的“node [fillcolor = COLOR]”语句中。
如果我只写“fillcolor =绿色,style =填充”而不是fillcolor = object1,则完全正常。同样,如果我用'Crimson'或任何其他颜色替换Green,也没有问题。
我的问题是,我希望这个颜色根据由条件确定的对象的值而改变。 基本上,如果太少的病人去看医生,这应该在我每天创建的报告中引起警报,并且每天手动编程有点麻烦。
我尝试过:
不是指定颜色,我正在尝试将条件对象的输出用作fillcolor(例如下面所示的内容)。
我希望最终的流程图框如果患病比例高于40%,则为绿色,如果低于40%则为深红色。感谢任何帮助!
问题出现在代码的“node [fillcolor = COLOR]”语句中。
如果我只写“fillcolor =绿色,style =填充”而不是fillcolor = object1,则完全正常。同样,如果我用'Crimson'或任何其他颜色替换Green,也没有问题。
我的问题是,我希望这个颜色根据由条件确定的对象的值而改变。 基本上,如果太少的病人去看医生,这应该在我每天创建的报告中引起警报,并且每天手动编程有点麻烦。
我尝试过:
不是指定颜色,我正在尝试将条件对象的输出用作fillcolor(例如下面所示的内容)。
# Just create some random data for a flow chart
a = 100 # Total people
b = 60 # Number of total that are sick
c = 19 # Number of sick that saw a doctor
d = round(c/b * 100) # percent of sick who saw a doctor
# create a flowchart-list-object
flow <- list(a=a, b=b, c=c, d=d)
# this could be where I am going wrong
# Condition that determines if the Percentage of sick people who saw a doctor
# is above 40%
if (d > 40) {
object1 <- 'Green'
} else
object1 <- 'Crimson'
# Output the flowchart using grViz
DiagrammeR::grViz("
digraph dot {
graph[layout = dot, fontsize = 15]
# Node numbers with labelled text
node [shape = box,
width = 3,
fontname = Helvetica]
a [label = '@@1']
b [label = '@@2']
c [label = '@@3']
# First set of node to edge connections
a -> b -> c
node [fillcolor = object1, style = filled]
d [label = '@@4']
c -> d
}
[1]: paste0('Total Sick \\n ', flow$a, '')
[2]: paste0('Number of total sick \\n ', flow$b, '')
[3]: paste0('Number of Sick who see a doctor \\n ', flow$c, '')
[4]: paste0('% of sick who see a doctor \\n ', flow$d, '')
")
我希望最终的流程图框如果患病比例高于40%,则为绿色,如果低于40%则为深红色。感谢任何帮助!