简体   繁体   中英

Export plot data from R to Excel

I have this plot which i generate it from this code:

m <- bcea(e=effects,c=costs, ref=2, interventions=treatments, Kmax=50000)

The plot is:

evi.plot(m)

Now, i need to export this evpi.plot(m) in an excel file, not the jpeg created, but the data along with it, i mean what created the X and Y axis.

I've been using something like this but it's not for this case

write.table( thresholds, 'clipboard', sep='\t', row.names=FALSE, col.names=FALSE )

In the documentation for function bcea from package BCEA you can see the structure of your object:

Value

An object of the class "bcea" containing the following elements

n.sim Number of simulations produced by the Bayesian model

n.comparators Number of interventions being analysed

...

k The vector of values for the grid approximation of the willingness to pay

...

evi The vector of values for the Expected Value of Information, as a function of the willingness to pay

And if you look at the function definition of evi.plot you will see that your x and y-values are the elements named k and evi :

> evi.plot
function (he) 
{
    options(scipen = 10)
    plot(he$k, he$evi, t = "l", xlab = "Willingness to pay", 
        ylab = "EVPI", main = "Expected Value of Information")
    if (length(he$kstar) > 0) {
        points(rep(he$kstar, 3), c(-10000, he$evi[he$k == he$kstar]/2, 
            he$evi[he$k == he$kstar]), t = "l", lty = 2, col = "dark grey")
        points(c(-10000, he$kstar/2, he$kstar), rep(he$evi[he$k == 
            he$kstar], 3), t = "l", lty = 2, col = "dark grey")
    }
}
<environment: namespace:BCEA>

So:

res <- cbind(m$k, m$evi)
write.table(res, file="bcea.csv", sep=',', row.names=FALSE, col.names=FALSE )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM