简体   繁体   English

在 1 plot 上绘制多个值

[英]Plotting several value on 1 plot

I have a data frame, where I want to plot Head against Time for the several depths on the 1 plot. The expected result is Plot of Pressure Head vs Time .我有一个数据框,我想要 plot Head against Time 1 plot 上的几个深度。预期结果是Plot of Pressure Head vs Time My data is:我的数据是:

data <- structure(
  list(
    Time = c(
      0,
      1343,
      1343,
      1343,
      1343,
      1348,
      1348,
      1348,
      1348,
      1353,
      1353,
      1353,
      1353,
      1358,
      1358,
      1358,
      1358,
      1363
    ),
    Node = c(
      231L,
      31L,
      61L,
      91L,
      231L,
      31L,
      61L,
      91L,
      231L,
      31L,
      61L,
      91L,
      231L,
      31L,
      61L,
      91L,
      231L,
      31L
    ),
    Depth = c(
      -2300,
      -300,-600,
      -900,
      -2300,
      -300,
      -600,
      -900,
      -2300,
      -300,
      -600,
      -900,-2300,
      -300,
      -600,
      -900,
      -2300,
      -300
    ),
    Head = c(
      -100,
      -203.46,-182.68,
      -199.26,
      -206.02,
      -207.96,
      -188.95,
      -203.36,
      -208.95,-159.2,
      -186.14,
      -198.17,
      -211.25,
      -45,
      -182.39,
      -191.23,
      -207.32,-31.66
    )
  ),
  row.names = 4:21,
  class = "data.frame"
)

I have already plotted it with the facet plots, in a way:我已经在某种程度上用刻面图绘制了它:

plot_node %>%
  mutate(
    facet = paste0(" Depth = -", abs(Depth), "mm")
  ) %>%
  ggplot(aes(Time)) +
  geom_line(aes(y= Head, color ="Matrix"))+
  labs(y= "Pressure Head [mm]")+
  ggtitle('Pressure Heads')+
  scale_x_continuous(limits = c(1348,1403), breaks = seq(1348,1403, 10)) +
  facet_wrap(vars(facet), ncol = 2, scales = "free") +
  theme_minimal() +
  theme(strip.text = element_text(size = 12, face = "bold"))

but in this way I can fit only 4 depthes on a facet plot, which is not quite usefull.但是通过这种方式,我只能在一个面 plot 上放置 4 个深度,这不是很有用。

Any ideas how I can implement it in R?有什么想法可以在 R 中实现吗?

PS: I now that the plots given in attched picture are done within Shell. PS:我现在所附图片中给出的情节是在Shell内完成的。

I think the x axis variable is constant across the range in your given data but your scale_x_continuous ranges from 1348 to 1403. For a line to be visible, you need both x and y to be changing.我认为 x 轴变量在您给定数据的范围内是恒定的,但您的 scale_x_continuous 范围从 1348 到 1403。要使一条线可见,您需要同时改变 x 和 y。

Assuming you have the right data, just use geom_line(aes(y= Head, l.netype=Depth)) instead of adding a facet_wrap()假设您有正确的数据,只需使用geom_line(aes(y= Head, l.netype=Depth))而不是添加facet_wrap()

I handled it in such way:我是这样处理的:

   plot_node<-node_data
plot_node <-filter(plot_node, Depth == -300 |
                                   Depth == -600 |
                                   Depth==-900 |
                                   Depth==-2300 )

plot_node$Time<-as.numeric(as.character(plot_node$Time))


plot_node %>%
  ggplot(aes(Time)) +
  scale_y_reverse()+
  scale_x_continuous(limits = c(1343,1440), breaks = seq(1343,1440, 20))+ 
geom_line(aes(y= Head, colour = as.factor(Depth)))+
   ylab("Pressure Head [mm]")+
  labs(color="Depth")

But still, is there any way to label the lines on the plot itself?但是,有什么办法可以 label plot 本身的线路吗? I want to put a number of depth on the line with the corresponding color.我想把一些深度放在对应颜色的线上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM