Re: [R] Plot in real unit (1:1)
Dar Jim, late, but it works now perfectly. I made a little function for autoscaling elevation data. https://stackoverflow.com/questions/50606797/plot-in-real-units-mm/52696705#52696705The (paper-)printer typically also autoscales, which needs to be deactivated. Example for a plot with scale in y and x direction: in2mm<-25.4 mx = 1000 # Scale X # input unit m my = 2000 # Scale Y # input unit m pdf("test_size.pdf",width=210/in2mm,height=297/in2mm,paper="special") par(mar= c(5.1,4.1,4.1,1.1)) pin <- par("pin") # returns plotheight and -width yvalue <- sort(sample(1:1000,200)) xvalue <- sort(sample(1:500,200)) xplus <- diff(range(c(0,pin[1]*in2mm)))*(mx/1000)/2 yplus <- diff(range(c(0,pin[2]*in2mm)))*(my/1000)/2 plot(xvalue,yvalue,#asp=mx/my, type="n", xaxs="i", yaxs="i", xlim=c(mean(xvalue)-xplus,mean(xvalue)+xplus), ylim=c(mean(yvalue)-yplus,mean(yvalue)+yplus), ylab="vertical [m]",xlab="horizontal [m]") lines(xvalue,yvalue,type="l",col="black") legend(x="topleft",horiz=TRUE, legend=c(paste0("Mx: 1:",mx),paste0("My: 1:",my), paste0("Vertical Exaggeration: 1:",mx/my)),x.intersp=0,bty="n") dev.off() On Thu, 2018-06-07 at 14:13 +1000, Jim Lemon wrote: > Hi Christian,Well, it almost worked. I suspect that the postscript > device adds somepadding to account for the printable area, so with a > bit ofexperimentation, The following example seems to do what you > want. WhenI printed the resulting file from the GIMP, the box and > diamond werethe correct dimensions. > postscript("test.ps",paper="a4",horizontal=FALSE)par(mai=c(1.713,0,1. > 713,0),xaxs="i",yaxs="i")plot(0,type="n",xlim=c(0,190),ylim=c(0,190), > xlab="",axes=FALSE)segments(c(0,95),c(95,0),c(190,95),c(95,190))segme > nts(c(45,95,145,95),c(95,145,95,45), > c(95,145,95,45),c(145,95,45,95))box()dev.off() > Jim > On Thu, Jun 7, 2018 at 8:16 AM, Jim Lemon > wrote:Hi Christian,When I have to do something like this, I usually > write it inPostscript using this: > /def mm 2.8346 mul > that converts a dimension in mm to points (1/72 inch). However, > thiswon't work in R. It may be possible to set up the device like > this: > postscript("myfile.ps",paper="a4")par(mar=c(0,0,0,0))# generate a > blank plotplot(0,type="n",xlim=c(0,210),ylim=c(0,297),axes=FALSE)# > display lines, etc. in mm with 0,0 at the bottom leftdev.off() > The resulting file should be printable. Warning, I don't have time > totest this right now. > Jim > > > On Thu, Jun 7, 2018 at 12:00 AM, Christian Brandstätter< > bran.c...@gmail.com> wrote:Dear List, > Is it possible to plot in R in "real" units? I would like to draw > aplot on A4 paper, where 1 plot unit would be a mm in reality. > Issomething like that possible? I would also like to be able to scale > theplot in x and y direction.Background: For a project I would have > to draw around 65 fast sketchesof elevation courves. > Copied from here, due to no answer: > https://stackoverflow.com/questions/50606797/plot-in-real-units-mm > Thank you! > __r-h...@r-project.org > mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the > posting guide http://www.R-project.org/posting-guide.htmland provide > commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Plot in real unit (1:1)
How about this: in2mm<-25.4 # scale factor to convert inches to mm pdf("test.pdf",width=8.3,height=11.7) pin<-par("pin") plot(c(0,pin[1]*in2mm),c(0,pin[2]*in2mm), type="n", xaxs="i", yaxs="i") lines(c(10,10),c(0,10)) text(11,5,"1 cm", adj=0) lines(c(0,40),c(20,20)) text(20,24,"4 cm") polygon(c(50,50,70,70),c(50,70,70,50)) text(60,60,"2x2 cm") dev.off() cheers Am 06.06.2018 um 16:00 schrieb Christian Brandstätter: > Dear List, > > Is it possible to plot in R in "real" units? I would like to draw a > plot on A4 paper, where 1 plot unit would be a mm in reality. Is > something like that possible? I would also like to be able to scale the > plot in x and y direction. > Background: For a project I would have to draw around 65 fast sketches > of elevation courves. > > Copied from here, due to no answer: https://stackoverflow.com/questions > /50606797/plot-in-real-units-mm > > Thank you! > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > -- Eik Vettorazzi Department of Medical Biometry and Epidemiology University Medical Center Hamburg-Eppendorf Martinistrasse 52 building W 34 20246 Hamburg Phone: +49 (0) 40 7410 - 58243 Fax: +49 (0) 40 7410 - 57790 Web: www.uke.de/imbe -- _ Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; Gerichtsstand: Hamburg | www.uke.de Vorstandsmitglieder: Prof. Dr. Burkhard Göke (Vorsitzender), Prof. Dr. Dr. Uwe Koch-Gromus, Joachim Prölß, Martina Saurin (komm.) _ SAVE PAPER - THINK BEFORE PRINTING __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Plot in real unit (1:1)
Thanks a lot! Jim Lemon schrieb am Do., 7. Juni 2018, 06:13: > Hi Christian, > Well, it almost worked. I suspect that the postscript device adds some > padding to account for the printable area, so with a bit of > experimentation, The following example seems to do what you want. When > I printed the resulting file from the GIMP, the box and diamond were > the correct dimensions. > > postscript("test.ps",paper="a4",horizontal=FALSE) > par(mai=c(1.713,0,1.713,0),xaxs="i",yaxs="i") > plot(0,type="n",xlim=c(0,190),ylim=c(0,190),xlab="",axes=FALSE) > segments(c(0,95),c(95,0),c(190,95),c(95,190)) > segments(c(45,95,145,95),c(95,145,95,45), > c(95,145,95,45),c(145,95,45,95)) > box() > dev.off() > > Jim > > On Thu, Jun 7, 2018 at 8:16 AM, Jim Lemon wrote: > > Hi Christian, > > When I have to do something like this, I usually write it in > > Postscript using this: > > > > /def mm 2.8346 mul > > > > that converts a dimension in mm to points (1/72 inch). However, this > > won't work in R. It may be possible to set up the device like this: > > > > postscript("myfile.ps",paper="a4") > > par(mar=c(0,0,0,0)) > > # generate a blank plot > > plot(0,type="n",xlim=c(0,210),ylim=c(0,297),axes=FALSE) > > # display lines, etc. in mm with 0,0 at the bottom left > > dev.off() > > > > The resulting file should be printable. Warning, I don't have time to > > test this right now. > > > > Jim > > > > > > > > On Thu, Jun 7, 2018 at 12:00 AM, Christian Brandstätter > > wrote: > >> Dear List, > >> > >> Is it possible to plot in R in "real" units? I would like to draw a > >> plot on A4 paper, where 1 plot unit would be a mm in reality. Is > >> something like that possible? I would also like to be able to scale the > >> plot in x and y direction. > >> Background: For a project I would have to draw around 65 fast sketches > >> of elevation courves. > >> > >> Copied from here, due to no answer: https://stackoverflow.com/questions > >> /50606797/plot-in-real-units-mm > >> > >> Thank you! > >> > >> __ > >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > >> https://stat.ethz.ch/mailman/listinfo/r-help > >> PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > >> and provide commented, minimal, self-contained, reproducible code. > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Plot in real unit (1:1)
Hi Christian, Well, it almost worked. I suspect that the postscript device adds some padding to account for the printable area, so with a bit of experimentation, The following example seems to do what you want. When I printed the resulting file from the GIMP, the box and diamond were the correct dimensions. postscript("test.ps",paper="a4",horizontal=FALSE) par(mai=c(1.713,0,1.713,0),xaxs="i",yaxs="i") plot(0,type="n",xlim=c(0,190),ylim=c(0,190),xlab="",axes=FALSE) segments(c(0,95),c(95,0),c(190,95),c(95,190)) segments(c(45,95,145,95),c(95,145,95,45), c(95,145,95,45),c(145,95,45,95)) box() dev.off() Jim On Thu, Jun 7, 2018 at 8:16 AM, Jim Lemon wrote: > Hi Christian, > When I have to do something like this, I usually write it in > Postscript using this: > > /def mm 2.8346 mul > > that converts a dimension in mm to points (1/72 inch). However, this > won't work in R. It may be possible to set up the device like this: > > postscript("myfile.ps",paper="a4") > par(mar=c(0,0,0,0)) > # generate a blank plot > plot(0,type="n",xlim=c(0,210),ylim=c(0,297),axes=FALSE) > # display lines, etc. in mm with 0,0 at the bottom left > dev.off() > > The resulting file should be printable. Warning, I don't have time to > test this right now. > > Jim > > > > On Thu, Jun 7, 2018 at 12:00 AM, Christian Brandstätter > wrote: >> Dear List, >> >> Is it possible to plot in R in "real" units? I would like to draw a >> plot on A4 paper, where 1 plot unit would be a mm in reality. Is >> something like that possible? I would also like to be able to scale the >> plot in x and y direction. >> Background: For a project I would have to draw around 65 fast sketches >> of elevation courves. >> >> Copied from here, due to no answer: https://stackoverflow.com/questions >> /50606797/plot-in-real-units-mm >> >> Thank you! >> >> __ >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Plot in real unit (1:1)
Hi Christian, When I have to do something like this, I usually write it in Postscript using this: /def mm 2.8346 mul that converts a dimension in mm to points (1/72 inch). However, this won't work in R. It may be possible to set up the device like this: postscript("myfile.ps",paper="a4") par(mar=c(0,0,0,0)) # generate a blank plot plot(0,type="n",xlim=c(0,210),ylim=c(0,297),axes=FALSE) # display lines, etc. in mm with 0,0 at the bottom left dev.off() The resulting file should be printable. Warning, I don't have time to test this right now. Jim On Thu, Jun 7, 2018 at 12:00 AM, Christian Brandstätter wrote: > Dear List, > > Is it possible to plot in R in "real" units? I would like to draw a > plot on A4 paper, where 1 plot unit would be a mm in reality. Is > something like that possible? I would also like to be able to scale the > plot in x and y direction. > Background: For a project I would have to draw around 65 fast sketches > of elevation courves. > > Copied from here, due to no answer: https://stackoverflow.com/questions > /50606797/plot-in-real-units-mm > > Thank you! > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Plot in real unit (1:1)
Dear List, Is it possible to plot in R in "real" units? I would like to draw a plot on A4 paper, where 1 plot unit would be a mm in reality. Is something like that possible? I would also like to be able to scale the plot in x and y direction. Background: For a project I would have to draw around 65 fast sketches of elevation courves. Copied from here, due to no answer: https://stackoverflow.com/questions /50606797/plot-in-real-units-mm Thank you! __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.