0

Currently I have a simulated data set describing the concentration-time profile of a drug at 10 different doses, with five replications ("subjects") for each dosing group. I am trying to create one file with plots for each dose, with the median concentration plotted as a dashed line, and a shaded confidence interval which I hoped to achieve with polygon().

# vector with the simulated doses
dvec <- c(0.1, 0.3, 1, 3, 10, 30, 100, 300, 500, 1000)

win.metafile("indv_plot.wmf", width = 25, height = 20)
  par(mfrow = c(2, 5))

for (bb in c(1:10)) {      
 ## sumdat is a data file which has summary statistics and CI 
 dose_d <- sumdat[sumdat$DOSE == dvec[bb], ]

 plot(dose_d$TIME, dose_d$OBS_MED,
       type = "n", lty = 2, col = "black",
       xlab = "Time (hr)", ylab = "Plasma Concentration",
       main = paste("DOSE=", dvec[bb]))
  polygon(c(dose_d$TIME, rev(dose_d$TIME)), c(dose_d$LPL_MED, rev(dose_d$UPL_MED)),
          col = "salmon", border = "red")
}

There are two problems I have when running this code:

  1. polygon() seems to be successful in generating the shaded region I want, but my dashed line is nohere to be seen on the graph. How do I appropriately overlay this so that both can be seen?
  2. In the .wmf file, the y-axes are extremely misleading (scaled so that each of the 10 graphs looks nearly identical!) and cut off part of the shaded region, such that you can no longer see the peak of the curve. How do I fix this scaling? Please note that the doses cover a 10k fold range.

enter image description here

EDIT: Here is a sample of the spreadsheet I'm working with with the numbers slightly different from the ones I'm working with.

DOSE    TIME    OBS_MED     LPL_MED     UPL_MED
0.1     0.25    0.00133825  0.001223836 0.002291141
0.1     0.5     0.001747625 0.002151059 0.003686252
0.1        1    0.00308325  0.003017057 0.005157501
0.1        2    0.003539375 0.003388839 0.005425594
0.1        3    0.002771875 0.003205603 0.004896142
0.1        5    0.002286875 0.002368057 0.003719701
0.1        7    0.0020495   0.00164708  0.002937914
0.1       12    0.001414625 0.000644596 0.001710477
30       0.25   0.760858151 0.275588118 0.470376128
30        0.5   0.749280163 0.468870272 0.774292746
30         1    1.264732715 0.677246853 1.069407039
30         2    1.219044091 0.769589233 1.148778861
30         3    1.084113451 0.70481485  1.06030292
30         5    1.014486376 0.527557896 0.791142911
30         7    0.600676092 0.368193808 0.610086631
30        12    0.287301205 0.138354359 0.371749849
jqn
  • 1
  • 2
  • If you want help with plotting, you really need to create a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input data so we can test as well. You don't have to include your actual data, but just a small, representative dataset that we can use to try the code and offer suggestions. – MrFlick Jul 17 '15 at 20:18
  • @MrFlick, thank you for the suggestion. I have included some above and hope that you will be able to reproduce what I have done and give me some pointers. – jqn Jul 17 '15 at 21:10

1 Answers1

1
  1. Your polygon is called to draw after the line is plotted. Without transparency in the polygon fill, there's no way you will see the line. Plot the polygon first.

  2. You are depending on the automatic axis choices made by the plot function, which are based on the limits of the line rather than of the polygon. You may specify your own limits as needed, as explained in the man pages.

EdM
  • 405
  • 4
  • 11
  • thank you for your response. However, I'm having some problems with it. I cannot add transparency to the polygon since it has this error: `semi-transparency is not supported on this device: reported only once per page` -- I'm running Windows 7 (64 bit), R version 3.2.1 (2015-06-18), and generating things in RStudio. When I plot the polygon first, I get this error, `plot.new has not been called yet` – jqn Jul 17 '15 at 21:19
  • Try proceeding as you had been in your original code but add yet another call to plot the line after the polygon is drawn. You might have to use `lines` instead of `plot` and/or use `add = TRUE` as a parameter to the last call to display your line over the polygon. (I always forget, and don't have easy access to the relevant man pages right now.) There is almost certainly a more elegant solution, but that should work. – EdM Jul 17 '15 at 21:45
  • thank you for your suggestion. Using `lines` worked perfectly for me, although it was redundant to plot something twice. – jqn Jul 20 '15 at 03:18