【问题标题】:Creating a horizontal bar chart in R to display sequence of activities在 R 中创建水平条形图以显示活动顺序
【发布时间】:2017-11-14 05:36:26
【问题描述】:

数据集“患者”是患者访问诊所并接受治疗的事件日志。下面的脚本给出了一个数据框,其中包含事件日志中的跟踪或活动序列、trace_id 和特定跟踪之后的案例的绝对频率。我希望使用ggplot2plotly 创建一个动态水平条形图,以便将轨迹表示为像带有轴标签的条形顶部的绝对频率百分比的快照。

谢谢,请帮忙!

library("bupaR")
traces(patients, output_traces = T, output_cases = F)

【问题讨论】:

  • 动态水平条形图是什么意思?
  • 就像在快照中显示的一样

标签: r ggplot2 plotly ggplotly visnetwork


【解决方案1】:

希望这会有所帮助(但是我无法获得频率)

library(splitstackshape)

tr <- data.frame(traces(patients, output_traces = T, output_cases = F))
tr.df <- cSplit(tr, "trace", ",")

tr.df <- tr.df[,c(1,4:9)]
tr.df <- melt(tr.df, id.vars = "trace_id")

windows()
ggplot(data = tr.df, aes(x = variable,y = trace_id, fill = value, label = 
value)) + 
geom_tile(colour = "white") + 
geom_text(colour = "white", fontface = "bold", size = 2) +
scale_fill_discrete(na.value="transparent") +
theme(legend.position="none")

编辑 1:

library(splitstackshape)
library(bupaR)
library(ggplot2)

tr <- data.frame(traces(patients, output_traces = T, output_cases = F))
tr.df <- cSplit(tr, "trace", ",")

tr.df <- tr.df[,c(1,4:9)]
tr.df <- melt(tr.df, id.vars = "trace_id")
tr.df <- tr.df[order(tr.df$trace_id),]

tr.label <- data.frame(id = tr$trace_id, freq = tr$absolute_frequency)
tr.label <- tr.label[order(tr.label$id),]

windows()
ggplot(data = tr.df, aes(x = variable,y = trace_id, fill = value, label = value)) + 
geom_tile(colour = "white") + 
geom_text(colour = "white", fontface = "bold", size = 2) +
scale_fill_discrete(na.value="transparent") +
theme(legend.position="none") + 
geom_text(data = tr.label, aes(label = freq, y = id, x = 6), nudge_x = 0.3,  
          colour = "black", fontface = "bold", inherit.aes = FALSE) 

【讨论】:

  • 非常好,效果很好,现在小小帮帮忙,我想去掉右边的数值标签,同时减少文字字体。另外,如果我想改变颜色,请帮我怎么做?很好的帮助。
  • 当然,我会那样做,只是那样,你能不能像上面那个快照那样给情节一些浅色,这个黄色看起来很亮。
  • 嘿哈迪克,需要更多调整,更新您的最新帖子,请帮助。
  • 请将您的编辑作为新段落添加到原文下方,请勿更改原始答案
猜你喜欢
  • 1970-01-01
  • 2023-01-15
  • 2011-07-06
  • 2015-07-09
  • 2018-03-11
  • 2012-03-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多