2015-10-31 37 views
0

标题我有一个名为“捕捉”数据和意见是:如何格式化GGPLOT2

x y 
0.50 3.66 
0.63 3.95 
0.77 5.82 
0.92 7.38 
1.07 8.58 
1.24 9.31 
1.42 9.52 
1.61 9.52 
1.81 9.58 
2.04 9.54 
2.29 9.56 
2.56 9.44 
2.87 9.07 
3.21 8.61 
3.61 7.92 
4.09 7.04 
4.67 5.93 
5.43 4.52 
6.52 2.90 
8.43 0.63 

我用这个代码R:

library(ggplot2) 
ccplot <- ggplot(data = catch, aes(x = x, y = y)) + 
      geom_point(shape = 19, colour = "#0072B2") 

ccplot <- ccplot + geom_abline(intercept = 14.58, slope = -1.85, col = "#D55E00") 

ccplot2 <- ccplot + 
      xlab("time") + 
      ylab(expression(paste("ln[C(L1, L2)]/(", Delta, "t)"))) 

ccplot2 + ggtitle(expression(paste("Length-Converted Catch Curve\n(for Z=1.85; M(at 23"*degree*"C)=0.69; F=1.16; E=0.63"), hjust = 0)) 

问题出现时,打印的图表在数字23和度数符号之间有一个很大的(遥远的)空间。

The plot printed with the above code

我如何格式化标题,这样的空间可以走了吗?或者有没有其他方法可以在ggplot2中完成正确的标题?

预先感谢您。

回答

2

在这种情况下,您最好使用unicode度符号而不是尝试使用plotmath。

ccplot2 + ggtitle(expression("Length-Converted Catch Curve\n(for Z=1.85; M(at 23\u00B0C)=0.69; F=1.16; E=0.63)"), hjust=0) 

你也使用atop()表达布局

ccplot2 + ggtitle(expression(atop("Length-Converted Catch Curve","(for Z=1.85; M(at 23"~degree~"C)=0.69; F=1.16; E=0.63)"))) 

什么是你的代码发生的事情是,它的打印第一串(新行),那么当你切换到数学模式程度,您退出字符串并开始在双线字符串的右侧。

+0

谢谢。但我还有其他问题。如果我将来自(对于Z = ...)的文本作为副标题,代码是否适用? – Cloud