--
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
#create simple dataframe for plotting xy <- data.frame(x=1:10, y=10:1) ggplot(data = xy)+ geom_point(aes(x = x, y = y))+scale_x_continuous(expression(paste("Estimated passage of ",italic("Fish fish"),"in 2001")))
From: Andrew Redd <amr...@gmail.com>
To: Felipe Carrillo <mazatla...@yahoo.com>
Cc: ggplot2 <ggp...@googlegroups.com>
Sent: Thu, January 20, 2011 12:22:09 PM
Subject: Re: partial italic axis titles
I figured out the bolditalic title problem, but now I am having problems with \n (newline). My X axis titleis long and would like to write it on two different lines. How can I use \n inside the function "expression"
You could hack opts() with a custom grob for the x axis title,
library(ggplot2)
my.title = function(...) {
g1 <- textGrob(expression(bold("first line")),
0.5, 1, hjust = 0.5, vjust = 2)
g2 <- textGrob(expression(italic("second line")), 0.5, 0,
hjust = 0.5, vjust = 3)
gTree(children=gList(g1, g2))
}
qplot(1,1, geom="blank") + opts(axis.title.x = my.title,
plot.margin = unit(c(1,1,3,1), "lines"))
HTH,
baptiste
On Thu, Jan 20, 2011 at 11:27 PM, Felipe Carrillo
library(gridExtra)
my.title = function(expressions) {
function(...)
tableGrob(expressions, parse=TRUE,
theme=theme.list(gpar.corefill = gpar(fill = NA, col = NA),
core.just = "center"))
}
e = expression(alpha,"testing", italic(italic),
hat(beta), integral(f(x)*dx, a, b))
qplot(1,1, geom="blank") + opts(axis.title.x = my.title(e))
HTH,
baptiste
library(ggplot2)
library(gridExtra)
my.title = function(expressions) {
function(...)
tableGrob(matrix(expressions), parse=TRUE,
theme=theme.list(gpar.corefill = gpar(fill = NA, col = NA),
core.just = "center"))
}
e = expression(alpha,"testing", italic(italic),
hat(beta), integral(f(x)*dx, a, b))
qplot(1,1, geom="blank") + opts(axis.title.x = my.title(e))
baptiste
On Fri, Jan 21, 2011 at 4:42 PM, Felipe Carrillo
What about atop("line one", "line two") ?
zw
gitalic puts the italic font right above the first line and appears to ignore
the vjust and hjust arguments.
Would you mind giving me a hint on how to go about this?
my.test = function(...) {
g1 <- textGrob(expression("Figure 20. Actual passage of pacific species"),0.5,
1, hjust = 0.5, vjust = 2)
gitalic <- textGrob(expression(italic("Penaeus
vannamei"),2,vjust=0.5,hjust=-3))
g2 <- textGrob(expression(italic("second line")), 0.5, 0,hjust = 0.5, vjust =
3)
gTree(children=gList(g1, gitalic,g2))
}
qplot(1,1, geom="blank") + opts(axis.title.x = my.test,
plot.margin = unit(c(1,1,3,1), "lines"))
library(gridExtra)
my.title = function(expressions) {
function(...)
tableGrob(matrix(expressions), parse=TRUE,
theme=theme.list(gpar.corefill = gpar(fill = NA, col = NA),
core.just = "center"))
}
title <- expression(paste("Figure 20. Actual passage of Pacific
species ", italic("Penaeus vannamei"),
" migrating to the San Francisco Bay"), italic("second line"))
qplot(1,1, geom="blank") + opts(axis.title.x = my.title(title))
That said, I would personally place the figure title outside of the
plot, not in the axis label,
library(gridExtra)
p <- qplot(1,1, geom="blank") + xlab("")
caption <- tableGrob(matrix(expression(paste("Figure 20. Actual
passage of Pacific species ", italic("Penaeus vannamei"),
" migrating to the San Francisco Bay"), italic("second line"))),
parse=TRUE, theme=theme.list(gpar.corefill =
gpar(fill = NA, col = NA),
core.just = "center"))
grid.arrange(p, sub=caption)
HTH,
baptiste