newline in expression

2,364 views
Skip to first unread message

scott_chamberlain

unread,
Oct 3, 2011, 1:14:32 PM10/3/11
to ggp...@googlegroups.com
Hello, 

I have searched for this topic and it appears that a newline can not be incorporated into expression() within a ggplot call directly (but can with use of gridextra I believe). 

I have a very simple case and just want a newline to separate the text from the x-axis by one line. 

For example: 
qplot(1,1, geom="blank") + 
  labs(x = expression(paste("Distribution of node ages, ", italic(gamma))))

produces the attached plot. I simply want that x-axis title one more line away from the axis. Apologies if I have missed an obvious solution. 

Thanks, Scott
Rplot.png

Brian Diggs

unread,
Oct 3, 2011, 1:32:08 PM10/3/11
to ggplot2

Newlines can't, but atop's can.

qplot(1,1, geom="blank") +

labs(x = expression(atop(,paste("Distribution of node ages, ",
italic(gamma)))))

I wouldn't consider it an obvious solution, but a hack that works.

> Thanks, Scott

--
Brian S. Diggs, PhD
Senior Research Associate, Department of Surgery
Oregon Health & Science University

scott_chamberlain

unread,
Oct 3, 2011, 5:32:54 PM10/3/11
to ggp...@googlegroups.com
Great! Thanks so much Brian. 

S

baptiste auguie

unread,
Oct 3, 2011, 5:41:42 PM10/3/11
to ggp...@googlegroups.com
Hi,

I may be missing something, but why do you need inserting a newline
rather than shifting the x title?

last_plot() + opts(axis.title.x = theme_text(vjust=-2),
plot.margin=unit(c(1, 1, 2, 0.5), "lines"))

b.

> --
> 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
>

scott_chamberlain

unread,
Oct 4, 2011, 11:18:30 AM10/4/11
to ggp...@googlegroups.com
Ahhh. Nice. I didn't think of just shifting the title position. 

Thanks so much Baptiste. 

Scott

patrick kilduff

unread,
Oct 3, 2011, 1:32:07 PM10/3/11
to ggp...@googlegroups.com
Hi Scott -

Using xlab() instead of labs(), move the axis label one line further from the plot for me.

qplot(1,1, geom="blank") + 
+   xlab(expression(paste("\nDistribution of node ages, ", italic(gamma)))

- Patrick 


From: scott_chamberlain <myrmec...@gmail.com>
To: ggp...@googlegroups.com
Sent: Monday, October 3, 2011 10:14 AM
Subject: newline in expression

Reply all
Reply to author
Forward
0 new messages