2

I am trying to create a base plot for a weibull probability plot. I have been exploring the survival package in R but have not found the exact tool I need yet. So far I have been able to recreate the plot I need by hand (which is terrible - tons of hard coding, it is not flexible at all and looks terrible).

My guess is that there is a package to create this base graph, with the grid lines, I just haven't discovered it yet.

This image is what I need to graph, it is called "Weibull probability plotting paper"

weibull paper

Is there a way in ggplot2 or within the survival package (or anything other that base R graphics) to create this plot? From there, I can overlay the points.

Please keep in mind the graphics I create in the end will need to be compatible with Shiny. Thank you.

For reference this is the ugly plot I have managed to create using ggplot2 by hand.

current_plot

Also, please note I cannot provide a reproducible code example since this is a very complex problem, I am looking for a basic reproducible base plot.

UPDATE

I am looking for a what to produce this plot, here is some examples of how I created mine by hand, please note it is not fully reproducible.

Here is how I set up the y-axis tick marks:

yticks <- c(log(-log(1-0.0001)), log(-log(1-0.001)), log(-log(1-0.005)), log(-log(1-0.010)), log(-log(1-0.05)), log(-log(1-0.10)),
        log(-log(1-0.50)), log(-log(1-0.90)), log(-log(1-0.99)))

Here are the y-labels:

ylabs <- c('0.01','0.1','0.5','1','5','10','50','90','99')

Here is how to create the minor grid lines:

yminorticks <- c(
  log(-log(1-0.00001)),log(-log(1-0.00002)),log(-log(1-0.00003)),log(-log(1-0.00004)),log(-log(1-0.00005)),log(-log(1-0.00006)),log(-log(1-0.00007)),log(-log(1-0.00008)),log(-log(1-0.00009)),
  log(-log(1-0.0001 )),log(-log(1-0.0002)),log(-log(1-0.0003)),log(-log(1-0.0004)),log(-log(1-0.0005)),log(-log(1-0.0006)),log(-log(1-0.0007)),log(-log(1-0.0008)),log(-log(1-0.0009)),
  log(-log(1-0.001)),log(-log(1-0.002)),log(-log(1-0.003)),log(-log(1-0.004)),log(-log(1-0.005)),log(-log(1-0.006)),log(-log(1-0.007)),log(-log(1-0.008)),log(-log(1-0.009)),
  log(-log(1-0.01)),log(-log(1-0.02)),log(-log(1-0.03)),log(-log(1-0.04)),log(-log(1-0.05)),log(-log(1-0.06)),log(-log(1-0.07)),log(-log(1-0.08)),log(-log(1-0.09)),
  log(-log(1-0.10)),log(-log(1-0.20)),log(-log(1-0.30)),log(-log(1-0.40)),log(-log(1-0.50)),log(-log(1-0.60)),log(-log(1-0.70)),log(-log(1-0.80)),log(-log(1-0.90)))
  • You just want a plot with log scales? When asking for help, you should include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Jul 02 '18 at 15:38
  • I cannot provide a reproducible example since I do not have a way of creating this plot. That is my question, how to create this base plot in a simple and reproducible manner. Thanks. –  Jul 02 '18 at 15:40
  • You created the plot "by hand" in ggplot. So share that code and data so we might do the same in perhaps a more efficient manor. – MrFlick Jul 02 '18 at 15:41
  • I could share that code but it will not be either simple or reproducible.. I can break it down into chunks though, some of which is reproducible. I am more looking to find out if there is a package that auto plots this. I have a hard time believing there is not. –  Jul 02 '18 at 15:43
  • Added code for how to create the minor grid lines, it's just a mess of `logs` to get it.. –  Jul 02 '18 at 16:00
  • 1
    Just an aside on your minor grid line code: `log`, and subtraction are all vectorized. vectorization means you can do, e.g., `log(-log(1 - seq(0.01, 0.09, by = 0.01)))` instead of `c(log(-log(1-0.01)),log(-log(1-0.02)),log(-log(1-0.03)),log(-log(1-0.04)), ... )` – Gregor Thomas Jul 02 '18 at 16:05
  • I have been researching this issue on google for weeks. Was hoping the knowledge pool on here could point me in the right direction. I have seen many people ask similar questions on here. –  Jul 02 '18 at 16:06
  • 2
    You can generate `yminorticks` with `yminorticks <- c(log(-log(1-outer(1:9, 10^(-5:-1)))))` rather than writing all that out. Though you probably want to be using `log10` rather than `log` – MrFlick Jul 02 '18 at 16:06
  • @RCoderForFun it seems like a minor point, but if you just ask "how do I get this result" rather than "is there a package that does this", your question will be on-topic and everyone will be happy. – Gregor Thomas Jul 02 '18 at 16:11
  • @Gregor will update to reflect that. –  Jul 02 '18 at 16:12
  • 1
    I think what you want to do for ggplot2 is define your own transformation with the scales package and use that with the `trans=` argument for `scale_x_continuous`. Here's an example where I do something similar to make a sign-restoring cox-box transformation https://github.com/ellisp/frs-r-package/blob/master/pkg/R/modulus-transform.R – Peter Ellis Jul 03 '18 at 02:55

1 Answers1

1

There is a package weibullR, which will help you to plot unreliability vs time.

library(WeibullR) 

df <- data.frame(time = c(10000, 10000, 20000, 20000, 30000, 30000, 30000, 30000, 
                          40000, 50000, 50000, 60000, 70000, 70000, 70000, 70000, 
                          80000, 80000, 80000, 80000, 90000, 90000, 100000), 
                 event = rep(1, 23)) 

weibl <- 1- wblr(df, 
                 col="darkgreen",
                 label="censored dataset",
                 dist = "weibull2p", 
                 ylab = "check") 

weibl_fit <- wblr.fit(weR, col = "Red", method.fit = "rr") 

data <- wblr.conf(weibl_fit, col="blue") 

plot(data)
Z.Lin
  • 28,055
  • 6
  • 54
  • 94
Lokesh kumar
  • 127
  • 1
  • 6