如何绘制较大的时间序列(数千个给药时间/药物剂量)? [英] How to plot large time series (thousands of administration times/doses of a medication)?

查看:106
本文介绍了如何绘制较大的时间序列(数千个给药时间/药物剂量)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图弄清楚医院如何开处方一种药物.在这个虚拟数据库中,在2017/01/01之后,我遇到了1000个患者.

I'm trying to plot how a single drug has been prescribed in the hospital. In this dummy database I have 1000 patient encounters after 2017/01/01.

标绘的目的是看该药物的给药方式:在入院,出院时间或患者住院期间更频繁/高剂量给药.

The goal of plotting is to see the pattern of administration of this drug: Is it given more frequently / high dose closer to time of admission, discharge, or in the middle of patient stay.

#Get_random_dates that we will use multiple times
gen_random_dates <- function(N, st, et) {
st <- as.POSIXct(as.Date(st))
et <- as.POSIXct(as.Date(et))
dt <- as.numeric(difftime(et,st,unit="sec"))
ev <- runif(N, 0, dt)
rt <- st + ev
return(rt)
}

#Generate admission and discharge dates
admission <- gen_random_dates(1000, "2017/01/01", "2017/01/10")
discharge <- gen_random_dates(1000, "2017/01/11", "2017/01/20")
patient <- sort(sample(1:1000, 1000))
patient_data <- data.frame(patient_ID = patient, admission_date = admission, discharge_date = discharge)

#Grow the database
patient_data <- patient_data[sort(sample(1000, 100000, replace=TRUE)), ] 

#Medication admin date and dose
patient_data$admin_date <- gen_random_dates(100000, patient_data$admission_date, patient_data$discharge_date)
patient_data$admin_dose <- abs(as.integer(rnorm(100000, 50, 100)))

我尝试了这个ggplot函数,但是它并没有帮助我可视化模式.

I tried this ggplot function but it did not help me visualize the pattern.

ggplot(patient_data, aes(x = admin_date, y = admin_dose)) +
  xlab("Use of Drug in Patient Encounters") + ylab("Dose (mg)") +
  geom_jitter()

ggplot

推荐答案

如果浏览器是可接受的目标,则一种方法是尝试常规R API . Plotly的图可以可视化很多点或线,这不仅是因为缩放/平移,而且在某些图类型中,还可以显示WebGL的背景,可以是

If a browser is an acceptable target, one option is to try ggplotly which enables panning/zooming, helpful with a time series with a lot of data. (Disclaimer, I'm a plotly.js maintainer.) Besides this, there's a regular R API to plotly.js. Plotly has plots that can visualize a lot of points or lines, not just due to zoom/pan but also, in some plot types, the backing of WebGL, which can be much faster.

这篇关于如何绘制较大的时间序列(数千个给药时间/药物剂量)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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