I think the code bellow illustrates what Martin is trying to say. Note that
although not considered in the example, everything works ok if labels are
not rotated.
In my opinion, especially after seeing Baptiste example (e.g. textGrob does
its job ok, even if you include rot = 90), this may be a bug in ggplot2.
Hope this helps,
fernando
library(ggplot2)
p <- qplot(1, 1) + scale_y_continuous(name = "A axis title")
p1 <- p + opts(axis.title.y = theme_text(size = 25, angle = 90, vjust = 0.5,
hjust = 0.5),
title = "vjust = 0.5, hjust = 0.5")
p2 <- p + opts(axis.title.y = theme_text(size = 25, angle = 90, vjust = 0.5,
hjust = 1),
title = "vjust = 0.5, hjust = 1")
p3 <- p + opts(axis.title.y = theme_text(size = 25, angle = 90, vjust = 1,
hjust = 0.5),
title = "vjust = 1, hjust = 0.5")
p4 <- p + opts(axis.title.y = theme_text(size = 25, angle = 90, vjust = 0,
hjust = 0.5),
title = "vjust = 0, hjust = 0.5")
pushViewport(viewport(layout = grid.layout(2, 2)))
print(p1, vp = viewport(layout.pos.row = 1, layout.pos.col = 1))
print(p2, vp = viewport(layout.pos.row = 1, layout.pos.col = 2))
print(p3, vp = viewport(layout.pos.row = 2, layout.pos.col = 1))
print(p4, vp = viewport(layout.pos.row = 2, layout.pos.col = 2))
-----Mensaje original-----
De: ggp...@googlegroups.com [mailto:ggp...@googlegroups.com] En nombre de
martin_kaercher
Enviado el: sábado, 24 de julio de 2010 22:47
Para: ggplot2
Asunto: hjust and vjust
Dear all,
Cheers,
Martin
--
You received this message because you are subscribed to the ggplot2 mailing
list.
Please provide a reproducible example: http://gist.github.com/270442
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2
This can be illustrated by comparing theme_text with an altered
version which keeps x=0.5, y=0.5:
library(ggplot2)
p <- qplot(1, 1, geom="blank") +
ylab("y-axis\ntitle") + theme_bw()
hvjust <- expand.grid(hjust=seq(0, 1, length=3),
vjust=seq(0, 1, length=3))
foo <- function(hjust = 0.5, vjust = 0.5, angle = 0)
{
vj <- vjust
hj <- hjust
structure(function(label, x = 0.5, y = 0.5, ..., vjust = vj,
hjust = hj, default.units = "npc") {
textGrob(label, x, y, hjust = hjust, vjust = vjust, ...,
default.units = default.units, rot = angle)
}, class = "theme", type = "text", call = match.call())
}
test <- function(hjust, vjust, fun=theme_text){
p + opts(axis.title.y = fun(angle = 90,
vjust = vjust, hjust = hjust),
title = paste("hjust:", hjust,
", vjust:", vjust, sep=""))
}
gl <- mlply(hvjust, test)
gl2 <- mlply(hvjust, test, fun=foo)
source("http://gridextra.googlecode.com/svn/trunk/R/arrange.r")
do.call(grid.arrange, gl)
# with foo, it's fine
do.call(grid.arrange, gl2)
Best,
baptiste
Martin H. Kärcher
Laboratory of Apiculture & Social Insects
Department of Biology & Environmental Science
School of Life Sciences
John Maynard Smith Building
University of Sussex
Brighton BN1 9QG, UK
landline (Austria): +43 316 382448
mobile (Austria): +43 650 3824481
landline (England): +44 127 387 7198
http://www.sussex.ac.uk/biology/profile220918.html