2017-11-14 23 views
0

데이터 세트 "환자"는 클리닉을 방문하여 치료를받는 환자의 이벤트 로그입니다. 아래의 스크립트는 이벤트 로그에 추적 또는 활동 시퀀스가있는 데이터 프레임, trace_id 및 특정 추적을 따르는 사례의 절대 빈도를 제공합니다. ggplot2 또는 plotly을 사용하는 동적 가로 막 대형 차트를 작성하여 축 레이블이있는 막대의 맨 위에 절대 빈도로 %로 첨부 된 스냅 샷과 같이 표시됩니다.활동 시퀀스를 표시하기 위해 R에 수평 막 대형 차트 만들기

감사합니다. 이 도움이

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

Trace Chart Explorer

+0

동적 가로 막 대형 차트 란 무엇입니까? –

+0

마치 스냅 샷 –

답변

0

희망 (I 그러나 주파수를 얻을 수 아니다)

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

enter image description here

편집 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) 

enter image description here

+0

에 표시되는 것과 같이 아주 좋았습니다. 이제는 작은 도움이되고, 오른쪽의 값 레이블을 제거하고 텍스트 글꼴을 줄이려고합니다. 또한 색상을 변경하려면 어떻게 할 지 알려주세요. 큰 도움. –

+0

편집을 확인하십시오 –

+0

도움이된다면 답을 upvote주세요. –