Subscript in the main title

2,649 views
Skip to first unread message

Nicippe B

unread,
Oct 1, 2013, 6:01:41 AM10/1/13
to ggp...@googlegroups.com
Hi All,

I have tried to add a main title with a subscript unsuccessfully. However, the subscript on the y axis was OK.  How can I do that? I also want to add a space between PM10 and µg/ m3 on y axis. Reproducible data and code is found below

Thanks

library(ggplot2)
library(reshape2)

PM10<- rnorm(365, 50, 25)
date<-seq(as.Date('2011-01-01'),as.Date('2011-12-31'),by = 1)
df<-data.frame(date,PM10)
dfmelt = melt(df, id.vars = 'date')

ggplot(dfmelt, aes(x = date, y = value)) +   
geom_line() +
labs(title=("Concentrations of PM[10] in 2012")) +
#theme(title = expression("Concentrations of PM[10] in 2012")) ,
ylab(expression(paste(PM[10], ("µg" / m^3)))) +
theme(plot.title = element_text(size = 17,face="bold" )) +
theme(axis.text=element_text(size=17),
axis.title=element_text(size=17,face="bold")) +
facet_wrap(~ variable, scales = 'free_y', ncol = 1)

David Guy

unread,
Oct 1, 2013, 8:41:58 AM10/1/13
to Nicippe B, ggplot2
Nicippe,

Here is what I think you want:

ggplot(dfmelt, aes(x = date, y = value)) +   
  geom_line() +
  labs(title=(expression(paste("Concentrations of ", PM[10], " in 2012")))) +
  #theme(title = expression("Concentrations of PM[10] in 2012")) ,
  ylab(expression(paste(PM[10]," ", ("µg" / m^3)))) +
  theme(plot.title = element_text(size = 17,face="bold" )) +
  theme(axis.text=element_text(size=17),
        axis.title=element_text(size=17,face="bold")) +
  facet_wrap(~ variable, scales = 'free_y', ncol = 1)

HTH

David


--
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility
 
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2
 
---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
David Guy, PhD
R Statistical Consulting Inc.
Flemington, NJ USA
 
Office: 908-237-5107
Cell:    917-941-5890
Fax:    908-284-0356
Skype: david.guy1213


Nicippe B

unread,
Oct 5, 2013, 1:42:21 PM10/5/13
to ggp...@googlegroups.com, Nicippe B
Thanks David, the code works perfectly!
Reply all
Reply to author
Forward
0 new messages