Replicating pdf layout for png output with plot.drc

Hello,

I am trying to replicate images plotted into a pdf as png files. I use the drc package for data analysis and plot with this package.

Here is some example code:

library(drc)

#y values
y <- c(102.951595194603, 100.847607393735, 74.649218346333, 59.448852705819,
49.3273721230525, 28.2010422250102, 0, 101.496908554261, 83.3736997281258,
30.4407625786927, 33.9671793614587, 32.3082156692324, 27.2386746113449, 0)
#x values
x <- c(0.0274348422496571, 0.0823045267489712, 0.246913580246914,
0.740740740740741, 2.22222222222222, 6.66666666666667, 20, 0.0274348422496571,
0.0823045267489712, 0.246913580246914, 0.740740740740741, 2.22222222222222,
6.66666666666667, 20)

curve <- drm(y ~ x, fct = LL.3()) #create a curve based on data above

pdf('example.pdf', width = 28, height = 18 ) #start png plotting device with graphical parameters
par(xpd = F, #ablines are underneath boxplot
mar = par()$mar + c(10,12,7,7), #margins
mgp = c(3,4,0)) #what does this?
par(mfrow=c(1,1)) #plots x rows and y columns of images into pdf

plot(curve, lwd = 10) plot curve
box(lwd = 7) plot box around curve

TList <- list(T1 <- "Text 1", T2 <- "Text 2", T3 <- "Text 3") #create list of text segments to be plotted underneath each other
for(r in 1:length(TList)){ plot all segments...
ins <- (r-1)*0.05 #with some vertical distance from each other...
legend('topright', inset = c(0, ins), #at the topright
legend=paste('Box: ',TList[[r]], sep=''),
lwd=6, cex=3, box.lty=0)
}
dev.off() #close plot device

###repeat it for a png device

png('example.png', units = "in", res = 100, width = 28, height = 18)
par(xpd = F, #ablines are underneath boxplot
mar = par()$mar + c(10,12,7,7), #margins
mgp = c(3,4,0)) #what does this?
par(mfrow=c(1,1)) #plots x rows and y columns of images into png

plot(curve, lwd = 10) plot curve
box(lwd = 7) plot box around curve

for(r in 1:length(TList)){ plot all segments...
ins <- (r-1)*0.05 #with some vertical distance from each other...
legend('topright', inset = c(0, ins), #at the topright
legend=paste('Box: ',TList[[r]], sep=''),
lwd=6, cex=3, box.lty=0)
}
dev.off() #close plot device

As you can see, I have some x and y data. With this, I create a drm object ("curve" variable) with the drc function. When I plot the object and put some legends at the top right, everything looks just fine. But when I plot the same object under the same conditions as a png file, the legend does not look the same but has some overlay (see image below).

I was wondering if anyone can tell me, why this is the case and how to solve this issue. I also tried to go another route by simply converting the pdf file into pngs… but this does not work either. You can see my problem here: Converting a pdf into several pngs

So, does anyone ave an idea, how to perfectly replicate the pdf layout?

Thanks, br,

Eike

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.