[R] centering axis labels in lattice

Paul Boutros paul.boutros at utoronto.ca
Fri May 8 17:08:51 CEST 2009


Hello,

I'm attempting to alter the location of text in my axis labels in  
lattice plots and have been unsuccessful so far.  For example, the  
y-axis labels are always right-justified, but I would like them to be  
horizontally centered.

Here's an example:
library(lattice);

# create fake dataset to plot
to.plot <- data.frame(
	x = 1:5,
	y = c("1\nAAA", "2\nBBB", "3\nCCC", "4\nDDD", "5\nEEE")
	);

# initial plot, note that the y-axis labels are right-justified
xyplot(
	y ~ x,
	to.plot,
	pch = 19,
	ylab = "",
	xlab = "",
	cex = 3
	);

# now try to set the positioning via scales
xyplot(
	y ~ x,
	to.plot,
	pch = 19,
	ylab = "",
	xlab = "",
	cex = 3,
	scales = list(
		labels = to.plot$y,
		hjust = 0.5,
		vjust = 0.5
		)
	);

I also explored using yscale.components.default(), but specifying  
hjust and vjust there did not help.  Any suggestions would be very  
much appreciated!

Paul

> sessionInfo();
R version 2.8.1 (2008-12-22)
i386-pc-mingw32

locale:
LC_COLLATE=English_United States.1252;LC_CTYPE=English_United  
States.1252;LC_MONETARY=English_United  
States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252

attached base packages:
[1] grid      stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] lattice_0.17-22




More information about the R-help mailing list