0

I am trying to make a scatter plot that contains two sets of data. Consequently, this means that the axis title is quite long and requires to be over two lines. I am able to do this but it seems to be interfering with the spacing on another bit of text in the axis title that I need to be superscript.It is adding additional spacing separating this bit of text from the rest of the label. If anyone had any suggestions to rectify this I would be very grateful.

Below I have included the code I am using. The particular line I am having trouble with is: ylab(expression(paste("mean water temperature (°C) &\n mean total solar (W/", m^2, ")"))). As I am a new user I was unable to post an image. I should mention I am fairly new to R so forgive the mess of code.

library(ggplot2) 
library(gtable)
library(grid)
library(reshape2)
library(gridExtra)

p <- ggplot(kom, aes(Date,AvgTotSol.5d.decawatts)) +
     stat_smooth(method="loess") +
     geom_point(shape =4, size = 4,  colour = "#339900") +
     geom_smooth(colour = "#339900") +
     scale_x_datetime(name="Date") + 
     scale_y_continuous() + 
     ylab(expression(paste("mean water temperature (°C) &\n mean total solar (W/", m^2, ")")))+
     geom_point(aes(Date,WatTempAvg.5d), shape = 2, size = 4, colour = "#cc0000")+ 
     geom_smooth(aes(Date,WatTempAvg.5d), colour = "#cc0000") +
     theme_bw(base_size = 18, base_family = "") +
     theme(plot.margin = unit(c(0.25, 12, 0.25, 2), "cm"))

k <- ggplot(kom, aes(Date,Fish.Lake.1)) + 
     stat_smooth(method="loess") + 
     geom_point(shape =0, size = 4, colour = "#000066") +
     geom_smooth(colour = "#000066")+
     scale_x_datetime(name="Date") + 
     scale_y_continuous()+
     ylab(expression(paste("y axis")))+
     theme_bw(base_size = 18, base_family = "") + 
     theme(plot.margin = unit(c(0.25, 12, 0.25, 2), "cm"))

grid.arrange(p, k, nrow = 2)
Wednesday
  • 9
  • 1
  • 2
    I don't have access to `kom` so I can't really speak to what's going on. Can you simulate some data (or use an existing dataset, see [here](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)) to demonstrate the problem? – Roman Luštrik Jun 02 '15 at 07:48
  • This might help: http://stackoverflow.com/questions/18237134/line-break-in-expression –  Jun 02 '15 at 07:55
  • 1
    Thanks for both your comments. I will keep in my mind that for future questions it is best to use data that is accessible to everyone. Pascal's comment answered my question. – Wednesday Jun 04 '15 at 05:06

0 Answers0