创建一个动态图表,显示R中计数的活动序列 [英] Creating a dynamic chart displaying sequences of activities with their count in R

查看:274
本文介绍了创建一个动态图表,显示R中计数的活动序列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您运行下面的R脚本,数据集患者是访问诊所并接受治疗的患者的事件日志。跟踪资源管理器按照下面的快照创建,并显示工具提示。现在,在频率百分比的#Script中,您可以获得af_percent列中每个轨迹的频率百分比。我的要求是,我只想用下面的ggplot命令中的label = value替换每个跟踪的相应频率百分比。

  library(splitstackshape)
library(scales)
library(ggplot2)
(库存)(plotly)
tr < - data.frame(traces(patients,output_traces = T,output_cases = F))
tr.df < - cSplit(tr,trace, )
tr.df $ af_percent< -
percent(tr.df $ absolute_frequency / sum(tr.df $ absolute_frequency))
pos< - c(1,4:ncol (tr.df))
tr.df< - tr.df [,.. pos]
tr.df< - melt(tr.df,id.vars = c(trace_id ,af_percent))
mp1 = ggplot(data = tr.df,aes(x = variable,y = trace_id,fill = value,
label = value))+
geom_tile color =white)+
geom_text(color =white,fontface =bold,size = 2)+
scale_fill_discrete(na.value =transparent)+
theme (legend.position =none)
ggplotly(mp1)

#频率百分比的脚本
tr =痕迹(患者,output_traces = T,output_cases = F)
tr $ af_percent = percent(te $ absolute_frequency / sum(te $ absolute_frequency))

(患者,output_traces = T,output_cases = F)

p < - trace_explorer(患者, (),
axis.ticks.x = element_blank(),
axis.text.y = element_blank(),
axis.ticks.y = element_blank())

gg< - ggplotly(p)

#与
#相同的方式,我们可以操纵任何其他阴谋对象
#请参阅https://plotly-book.cpsievert.me/extending-ggplotly.html
布局(gg,margin = list (l = 50,b = 50),legend = list(x = 1.05))


If you run the R script below, the dataset "patients" is an eventlog of patients visiting a clinic and getting treatment. The trace explorer gets created as in the snapshot below with the tooltip displayed. Now in the "#Script for Frequency Percentage", you get the frequency percentage for each trace in the column "af_percent". My requirement is that, I just want to replace the "label = value" in the ggplot command below with corresponding frequency percentage of each trace. Please help.

library(splitstackshape)
library(scales)
library(ggplot2)
library(plotly)
tr <- data.frame(traces(patients, output_traces = T, output_cases = F))
tr.df <- cSplit(tr, "trace", ",")
tr.df$af_percent <-
percent(tr.df$absolute_frequency/sum(tr.df$absolute_frequency))
pos <- c(1,4:ncol(tr.df))
tr.df <- tr.df[,..pos]
tr.df <- melt(tr.df, id.vars = c("trace_id","af_percent"))
mp1 = 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")
ggplotly(mp1)

#Script for Frequency Percentage
tr = traces(patients, output_traces = T,output_cases = F) 
tr$af_percent = percent(te$absolute_frequency/sum(te$absolute_frequency))

解决方案

library(bupaR)
library(plotly) 

traces(patients, output_traces = T, output_cases = F)

p <- trace_explorer(patients,type = "frequent", coverage = 1) +
theme(axis.text.x=element_blank(),
      axis.ticks.x=element_blank(),
      axis.text.y=element_blank(),
      axis.ticks.y=element_blank())

gg <- ggplotly(p)

# Now manipulate the plotly object in the same way that 
# we would manipulate any other plotly object
# See https://plotly-book.cpsievert.me/extending-ggplotly.html
layout(gg, margin=list(l=50, b=50), legend=list(x=1.05))

这篇关于创建一个动态图表,显示R中计数的活动序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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