PJP - 2 months ago 42
R Question

# Using R to calculate trumpet curves from flow data

I'm looking for a way to calculate Trumpet Curves from intravenous set flow data using (and preferably ggplot2 although that's not vital). These are curves based on flow rate data from IV pumps.

See http://www.australianprescriber.com/magazine/18/2/49/51/ for an example of a trumpet curve.

Any help much appreciated.

Pete

Here is some flow data (much faster than IV pumps - from fluid warming pumps (I mistakenly said gravity flow previously) which are high flow but same sort of patterns): http://pastebin.com/vJmGcJmn

So far I have this:

``````flow<-read.table(file="flow.dat",header=T)
flow\$diff<-c(0,diff(flow\$Mass))
ggplot(data=flow, aes(x=Secs,y=diff)) + geom_line()
``````

Note that the trumpet graphs required are as per ISO 60601-2-24 (if that means anything!)

This flow was set up at 150ml/minute.

Sorry this took so long, pressed for time.

The data you provided don't seem to fit your description of what the trumpet curve's suppose to represent or I'm missing something big. I would appreciate it if you could, in short, describe what needs to be done with the data.

When you manage to shape your data for output, you can stick it into the code below and it should produce a plot. I'll make it up to you to customize it to your needs.

``````# generate some random data
trump <- data.frame(
curve1 = rev(sort(rchisq(100, df = 2))) * rnorm(100, mean = 5, sd = 0.1) + 3,
curve2 = -rev(sort(rchisq(100, df = 2))) * rnorm(100, mean = 5, sd = 0.1) - 3
)
trump <- trump[seq(from = 1, to = 100, by = 3), ]

ggplot(trump, aes(x = 1:nrow(trump), y = curve1)) +
geom_line() +
geom_point() +
geom_line(aes(y = curve2)) +
geom_point(aes(y = curve2)) +
geom_hline(aes(yintercept = 0), linetype = "solid") + # overall percentage error
geom_hline(aes(yintercept = 5), linetype = "dashed") + # set rate
xlab("Observation windows (in minutes)") +
ylab("% error") +
annotate("text", x = 8, y = -1.5, label = "overall percentage error") +
annotate("text", x = 5, y = 3, label = "set rate") +
annotate("text", x = 10, y = -24, label = "min. error") +
annotate("text", x = 10, y = 24, label = "max. error") +
theme_bw()
``````