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!
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
<bran.chri at gmail.com> 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 at 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.
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 <drjimlemon at gmail.com>
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
> <bran.chri at gmail.com> 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 at 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.
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 at 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