手动设置R中每个变量的x轴限制

时间:2017-09-01 13:47:25

标签: r ggplot2

我有数据

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")

有了这个,我得到以下情节。

enter image description here

有没有办法手动设置每个变量的x轴限制?比如温度+ xlim(20, 40)。和盐度和荧光相似

0 个答案:

没有答案