Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Line break in TeX()? #8

Closed
caijun opened this issue Nov 21, 2017 · 2 comments
Closed

Line break in TeX()? #8

caijun opened this issue Nov 21, 2017 · 2 comments

Comments

@caijun
Copy link

caijun commented Nov 21, 2017

I would like to add a line break in the plot title using the LaTeX command \newline, however it didn't produce the figure as expectation.

library(plyr)
library(ggplot2)
x <- seq(0, 4, length.out=100)
alpha <- 1:5
data <- mdply(alpha, function(a, x) data.frame(v=a*x^a, x=x), x)

p <- ggplot(data, aes(x=x, y=v, color=X1)) +
  geom_line() + 
  ylab(TeX('$\\alpha  x^\\alpha$, where $\\alpha \\in 1\\ldots 5$')) +
  ggtitle(TeX('Using $\\LaTeX$ for plotting in ggplot2. $\\newline$ I $\\heartsuit$ ggplot!')) +
  coord_cartesian(ylim=c(-1, 10)) +
  guides(color=guide_legend(title=NULL)) +
  scale_color_discrete(labels=lapply(sprintf('$\\alpha = %d$', alpha), TeX)) 

print(p)

image

@stefano-meschiari
Copy link
Owner

Hi caijun, I can add support for that. In the meantime, you should be able to simply use \n to force a newline.

@caijun
Copy link
Author

caijun commented Nov 21, 2017

I tried \n, but it didn't work.

library(plyr)
library(ggplot2)
x <- seq(0, 4, length.out=100)
alpha <- 1:5
data <- mdply(alpha, function(a, x) data.frame(v=a*x^a, x=x), x)

p <- ggplot(data, aes(x=x, y=v, color=X1)) +
  geom_line() + 
  ylab(TeX('$\\alpha  x^\\alpha$, where $\\alpha \\in 1\\ldots 5$')) +
  ggtitle(TeX('Using $\\LaTeX$ for plotting in ggplot2. \n I $\\heartsuit$ ggplot!')) +
  coord_cartesian(ylim=c(-1, 10)) +
  guides(color=guide_legend(title=NULL)) +
  scale_color_discrete(labels=lapply(sprintf('$\\alpha = %d$', alpha), TeX)) 

print(p)

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants