在 R 中创建水平条形图以显示活动序列

2023-12-20

数据集“患者”是患者访问诊所并接受治疗的事件日志。下面的脚本提供了一个数据帧,其中包含事件日志中的跟踪或活动序列、trace_id 以及特定跟踪之后的案例的绝对频率。我希望使用创建动态水平条形图ggplot2 or plotly这样,迹线的表示方式就像在带轴标签的条形顶部附加有绝对频率(以 % 表示)的快照一样。

谢谢并请帮忙!

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

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

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")

EDIT 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) 
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在 R 中创建水平条形图以显示活动序列 的相关文章

随机推荐

  • 无法应用插件 Android Gradle 插件 3.0.0-alpha5 不得应用于项目

    使用最新的Android Studio 3 0 Canary 5 这是错误 错误 1 1 评估项目 app 时出现问题 无法应用插件 类 com android build gradle api AndroidBasePlugin Andr
  • 卡片上的 Ionic 长按事件

    如何在 Ionic 中为卡片设置长按事件以启动特定卡片的操作表 帮我在 ionic 中绑定这个长按事件 Ionic 4 种手势 安装 HammerJs npm install hammerjs 里面 src main ts Hammerjs
  • 何时使用 GenericServlet 而不是 HttpServlet?

    我知道 GenericServlet 是独立于协议的 并且是一个抽象类 所以我的问题是 什么时候有人会选择使用 GenericServlet 您是否知道任何使用 GenericServlet 的具体示例 我总是将 servlet 与 HTT
  • 执行“npm install”后安装了太多 npm 模块

    My package json name thumbnaillist gulp version 1 0 0 description main index js scripts test echo Error no test specifie
  • 其实例类型“BrowserRouter”不是有效的 JSX 元素

    我正在开发一个用 React coreui 开发的项目 该项目一直运行良好 然而 上周我在部署修改时遇到了一个莫名其妙的问题 18 03 11 Creating an optimized production build 18 04 32
  • IOS模拟器中双击不工作

    我在尝试着double tapIOS模拟器中的一个元素使用appium但无法这样做 Methods tried action tap x xx y yy count 1 release perform 连续2次 但似乎有2秒的间隙 这在现实
  • r - tag$head 中的错误:“closure”类型的对象不可取子集

    当我在笔记本电脑上运行 Shiny 应用程序时 出现此错误 在我使用库 git2r 添加一行代码之前 应用程序就可以工作了 下面是我的代码 有人可以帮忙吗 谢谢 ui R league desc lt c Premier League Se
  • Unity 2019.3.0a7:Microsoft Visual C# 编译器错误

    我已升级到最新的 Unity 版本 Unity 2019 3 0a7 但在不同的文件中却遇到了大量错误 与我合作的朋友也运行相同的版本 但没有出现错误 其中有两个 每个引用不同的包 但都引用每个包内的多个错误 错误大致如下 R Visual
  • 添加验证到 Angular 材质禁用字段

    简化的场景是在我的表单上有两个字段 A 和 B 字段 A 是必需的并且已启用 字段 B 也是必需的 但被禁用 并且仅作为字段 A 中键入的数据的结果而填充 动态 并且在某些情况下 B 可能会解析为 NULL 除非两个字段都已填充 否则用户应
  • 在url中使用下划线连接组合键是好还是坏设计?

    我正在为以下用例寻找 RESTful API 设计的最佳实践 Table1 Table2 Id1 Id1 Id2 Id2 Id3 Id3 Name Name Table1Id1 FK to Table1 Table1Id1 FK to Ta
  • 使用 pandas reindex 和 float:插值

    你能解释一下这种奇怪的行为吗 df pd DataFrame year 1986 1987 1988 bomb arange 3 set index year In 9 df reindex arange 1986 1988 125 125
  • 在mongo查询中将iso日期转换为时间戳

    这是查询 project formattedDate dateToString format Y m d date ceatedAt createdAtMonth month ceatedAt rating 1 group id forma
  • Nodejs无法连接到云shell上的mongodb

    我的 MongoDB 服务器托管在 google cloud VM 上 我希望创建 App Engine 微服务 测试连接性 我的 server js 看起来像 const MongoClient require mongodb Mongo
  • 如何使用 Spark 查找 10 亿条记录的最近邻居?

    给定 10 亿条记录 其中包含以下信息 ID x1 x2 x3 x100 1 0 1 0 12 1 3 2 00 2 1 1 2 2 3 对于上面的每个 ID 我想根据向量的欧几里德距离 x1 x2 x100 找到前 10 个最接近的 ID
  • 在 JavaScript 中重复某个字符串多次

    在 Perl 中 我可以使用以下语法多次重复一个字符 a a x 10 results in aaaaaaaaaa 有没有一种简单的方法可以在 Javascript 中实现这一点 显然我可以使用一个函数 但我想知道是否有任何内置方法或其他一
  • 自动输入 Python 提示

    我正在尝试编写一个 python 脚本 它将为我执行 bash 命令行程序 该程序要求用户输入两次 我希望我的脚本每次都自动输入 1 我听说过这样的事情 os system program lt prepared input 如何编写pre
  • q-learning计算中的大量状态

    我通过 q learning 实现了一款 3x3 OX 游戏 它在 AI vs AI 和 AI vs Human 中完美运行 但我无法更进一步地进行 4x4 OX 游戏 因为它会耗尽我所有的 PC 内存并崩溃 这是我当前的问题 大数组中的访
  • 根据优先级映射数据框列

    我有一个主数据框 main df 例如 A B X Y Id1 0 cat cat1 catabc 0 1 uuid01 1 cat cat1 catxyz 0 4 uuid02 2 cat cat2 catpqr 0 5 uuid01 3
  • Javascript - 按日期然后按时间对对象数组进行排序

    我有以下数组 id 1 value value1 date 2018 08 08 time 15 27 17 id 2 value value2 date 2018 08 09 time 12 27 17 id 3 value value3
  • 在 R 中创建水平条形图以显示活动序列

    数据集 患者 是患者访问诊所并接受治疗的事件日志 下面的脚本提供了一个数据帧 其中包含事件日志中的跟踪或活动序列 trace id 以及特定跟踪之后的案例的绝对频率 我希望使用创建动态水平条形图ggplot2 or plotly这样 迹线的