[R] Plot in real unit (1:1)
Christian Brandstätter
br@n@chri @ending from gm@il@com
Mon Oct 8 09:22:30 CEST 2018
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 <drjimlemon using gmail.com>
> 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.chri using 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-help using 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]]
More information about the R-help
mailing list