[R] R units of margins, text and points in a figure
Jim Lemon
drjimlemon at gmail.com
Tue Nov 10 09:48:59 CET 2015
Hi Gudrun,
Let's see. First, the "cex" argument means character _expansion_, not an
absolute size. So as the symbols and letters start out different sizes,
that proportional difference remains as they are expanded. The size of text
depends a bit upon the font that is being used. Perhaps if you determine
the expansions necessary to get the "A" the same size as the pch=20 symbol
(I get about two and one half times the expansion for the symbol as for the
letter) you can write this into your code.
Margins are another unit, the number of lines (vertical space required for
a line of text). This is somewhat larger than the actual vertical extent of
the letters as there is a space left between lines. If you change the
device (eg from PNG to PDF) you will probably encounter yet another change
in the apparent size of things. I suggest using the eyeball method to work
out the proportions for the device you want to use and be prepared to
change things if you move to another graphics device.
Jim
On Tue, Nov 10, 2015 at 7:15 PM, Gygli, Gudrun <gudrun.gygli at wur.nl> wrote:
> Dear R-help,
>
>
> I am trying to plot some data in a plot where I leave a big margin free to
> add other information, namely text and points.
>
> I am now struggling with keeping the size of the margin, text and points
> in a fixed ratio. I want this so that the layout of the figure does not
> change every time I plot new data.
>
> I have:
>
> a<-8
> counter<-1
> spacing<-a/(3*a)
> adding<-a/(3*a)
> start<-a*(a/3)
>
> alphabet<-c("A","A","A","A","A","A","A","A")
> x<-c(1,2,3,4,5,6,7,8)
> y<-c(10,20,30,40,50,60,70,80)
> png(file="TESTING.png", units="in", width=a, height=a, res=a*100)
> par(xpd=NA,mar=c(0,0,0,0),oma=c(0,0,0,(3*a))) #bottom, left,top, right
>
> plot.new()
> plot(x,y)
> points(pch=20,10, 10, cex=5)
> text(10,10, alphabet, cex=5, col="blue")
>
> What I do not understand is why the size of the point and the text is not
> the same and why the margin can be "bigger" than the width of the figure.
>
> BASICALLY, the units of the margins, the points and the text are not the
> same...
>
> What I need is a way to make the size of the point and text AND the margin
> independent of the data I plot so that the figure always looks the same
> although there is more data in it in some cases (for example 10 or 20
> points with text in the margin).
>
> This could be done by setting the units of points, text and margin to
> inches so that a is the same for all of them... Or to know the ratio
> between the different units used by R for margin, points and text...
>
> Any ideas on how to solve that?
>
> Please let me know if clarifications are needed!
>
>
> Gudrun
>
>
>
>
>
>
>
> Gudrun Gygli, MSc
>
> PhD candidate
>
> Wageningen University
> Laboratory of Biochemistry
> Dreijenlaan 3
> 6703 HA Wageningen
> The Netherlands
>
> Phone 31 317483387
> e-mail: gudrun.gygli at wur.nl
>
> - - - - - - - - - - - - - - - - - -
>
> Project information:
> http://www.wageningenur.nl/en/show/Bioinformatics-structural-biology-and-molecular-modeling-of-Vanillyl-Alcohol-Oxidases-VAOs.htm
>
> ______________________________________________
> 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.
>
[[alternative HTML version deleted]]
More information about the R-help
mailing list