Ajay Narottam Shah
2005-Oct-01 07:32 UTC
[R] Placing axes label strings closer to the graph?
Folks,
I have placed an example of a self-contained R program later in this
mail. It generates a file inflation.pdf. When I stare at the picture,
I see the "X label string" and "Y label string" sitting
lonely and far
away from the axes. How can these distances be adjusted? I read ?par
and didn't find this directly.
I want to hang on to 2.8 x 2.8 inches as the overall size of graph,
but it will be nice if the inner square frame was bigger and thus the
axes were closer to the strings. I will be happy with (say)
par(mai=c(.6,.6,.2,.2)). But if I just do this, the "X label string"
and "Y label string" were lost.
Thanks,
-ans.
D <- structure(list(dates = c(1983, 1984, 1985, 1986, 1987, 1988,
1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996,
1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
2005), inflation = c(7.6, 12.1, 6.3, 6.8, 8.7,
8.8, 9.4, 6.1, 11.6, 13.5, 9.6, 7.5, 10.1, 10.2,
9.3, 7, 13.1, 3.4, 3.7, 4.3, 4.1, 3.7, 4)),
.Names = c("dates", "inflation"), row.names
c("1", "2", "3", "4", "5",
"6", "7", "8", "9",
"10", "11", "12", "13",
"14", "15", "16", "17",
"18", "19", "20", "21",
"22", "23"), class "data.frame")
pdf(file="inflation.pdf", width=2.8, height=2.8,
bg="cadetblue1")
par(mai=c(0.8,0.8,0.2,0.2))
plot(D$dates, D$inflation, xlab="X label string", ylab="Y label
string",
type="l", lwd=2, col="cadetblue4", cex.axis=0.6,
cex.lab=0.6)
--
Ajay Shah Consultant
ajayshah at mayin.org Department of Economic Affairs
http://www.mayin.org/ajayshah Ministry of Finance, New Delhi
Prof Brian Ripley
2005-Oct-01 10:28 UTC
[R] Placing axes label strings closer to the graph?
Use mtext() to put labels in the margin line you want. title() writes
xlab and ylab in line 3 AFAIR. So you could use something like
par(mai=c(0.6,0.6,0.2,0.2))
plot(D$dates, D$inflation,
type="l", lwd=2, col="cadetblue4", cex.axis=0.6)
mtext("X label string", 1, line=2, cex = 0.6)
mtext("Y label string", 2, line=2, cex = 0.6)
*However*, your error is to use cex to change the font size, not pointsize
(which scales the lines suitably). Try instead
pdf(file="inflation.pdf", width=2.8, height=2.8, pointsize=6)
plot(D$dates, D$inflation, xlab="X label string", ylab="Y label
string",
type="l", lwd=2, col="cadetblue4")
On Sat, 1 Oct 2005, Ajay Narottam Shah wrote:
> Folks,
>
> I have placed an example of a self-contained R program later in this
> mail. It generates a file inflation.pdf. When I stare at the picture,
> I see the "X label string" and "Y label string" sitting
lonely and far
> away from the axes. How can these distances be adjusted? I read ?par
> and didn't find this directly.
>
> I want to hang on to 2.8 x 2.8 inches as the overall size of graph,
> but it will be nice if the inner square frame was bigger and thus the
> axes were closer to the strings. I will be happy with (say)
> par(mai=c(.6,.6,.2,.2)). But if I just do this, the "X label
string"
> and "Y label string" were lost.
>
> Thanks,
>
> -ans.
>
> D <- structure(list(dates = c(1983, 1984, 1985, 1986, 1987, 1988,
> 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996,
> 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
> 2005), inflation = c(7.6, 12.1, 6.3, 6.8, 8.7,
> 8.8, 9.4, 6.1, 11.6, 13.5, 9.6, 7.5, 10.1,
10.2,
> 9.3, 7, 13.1, 3.4, 3.7, 4.3, 4.1, 3.7, 4)),
> .Names = c("dates", "inflation"),
row.names > c("1", "2", "3",
"4", "5", "6", "7", "8",
"9",
> "10", "11", "12",
"13", "14", "15", "16", "17",
> "18", "19", "20",
"21", "22", "23"), class >
"data.frame")
>
> pdf(file="inflation.pdf", width=2.8, height=2.8,
bg="cadetblue1")
> par(mai=c(0.8,0.8,0.2,0.2))
> plot(D$dates, D$inflation, xlab="X label string", ylab="Y
label string",
> type="l", lwd=2, col="cadetblue4", cex.axis=0.6,
cex.lab=0.6)
>
> --
> Ajay Shah Consultant
> ajayshah at mayin.org Department of Economic Affairs
> http://www.mayin.org/ajayshah Ministry of Finance, New Delhi
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html
>
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595