1

I have a data

df <- structure(list(ID = 1:14, Depth = c(0, 3.1, 3.5, 4.3, 7.5, 8.2, 
10, 9.1, 7.3, 5.2, 4.5, 3.3, 2.5, 0), Salinity = c(1.3, 1.4, 
2, 2.6, 2.9, 2.1, 2.6, 2.6, 2.7, 3.2, 2, 2.3, 1.8, 1.5), Temperature = c(29.2, 
29.2, 29.2, 29.2, 29.4, 29.1, 29.1, 29.1, 28.9, 29, 29, 29.1, 
29.1, 29.1), Time = c("13:44:23", "13:44:26", "13:44:30", "13:44:34", 
"13:44:37", "13:44:41", "13:44:44", "13:44:48", "13:44:52", "13:44:55", 
"13:44:59", "13:45:03", "13:45:06", "13:45:10"), fluorescence = c(152L, 
175L, 149L, 192L, 174L, 154L, 147L, 150L, 147L, 180L, 167L, 154L, 
106L, 136L)), .Names = c("ID", "Depth", "Salinity", "Temperature", 
"Time", "fluorescence"), row.names = c(NA, -14L), class = c("data.table", 
"data.frame"))

meltdf <-  mutate(df, trend = c(rep("UP",7), rep("DOWN",7)))

moremelt <- meltdf %>%
           gather(key, value, Salinity, Temperature, fluorescence)
library(tidyverse)

ggplot(moremelt, aes(x = value, y = Depth, color = interaction(trend,key), label=key)) + 
     geom_line(lwd=2) +
     scale_colour_manual(values=c("orange","red","blue","cyan","black","grey")) +
     facet_wrap(~key, nrow=3, scale="free")

With this, I get the following plot.

enter image description here

Is there a way to manually set the the x-axis limit for each of the variables? like + xlim(20, 40) for temperature for example. and similarly to salinity and fluorescence

jazzurro
  • 23,179
  • 35
  • 66
  • 76
K. Maya
  • 289
  • 1
  • 8
  • [This answer](https://stackoverflow.com/a/21585521/2461552) gives you an idea of how to proceed, using a new dataset and `geom_blank`. Putting the `color` and `label` aesthetics into `geom_line` rather than setting them globally will help. A new dataset for the `Temperature` limits could look like `data.frame(value = c(20, 40), Depth = range(moremelt$Depth), key = "Temperature")` – aosmith Sep 01 '17 at 13:58
  • @aosmith and is there a way that in the x-axis instead of value i insert something else like ppt for salinity and °C for temperature and so on – K. Maya Sep 02 '17 at 13:58
  • Don't think so but not sure; maybe ask a new question. You could add the units to the strip labels, though. – aosmith Sep 02 '17 at 14:36

0 Answers0