0
votes

Ola, I have a question concerning ggplot.

In this code I have 31 days and each day has around 200 measured times with a precipitation sum.

Delay is measured in seconds, Precip in mm (times 100, for plotting measures).

The code below is just so you can get a good view on this.

I'm currently struggling to form this into a ggplot graph.

  X    ARRIVAL    DELAY    PRECIP    DATDEP
  1    08:12      -10       0        01AUG2019
  2    11:22      120       19.2222  01AUG2019
  3    09:22      22        0.4444   01AUG2019
  4    21:22      0         33.2222  01AUG2019
  5    08:22      2         744.4444 02AUG2019
          etc. etc. 

How do I manage to plot this month into a plot with 2 lines (one for DELAY and one for PRECIP)? I can't manage to transform the DATDEP into a nice time frame on the x-axis.

Q2: also for for example 4 months? How would you manage to form that into a nice time frame on the x-axis.

1
DATA %>% mutate(DAY=substr(DATDEP, 1, 2) %>% ggplot() + geom_line(aes(x=DAY, y=DELAY)) + geom_line(aes(x=DAY, y=PRECIP)) etc. etc.Edward
@Edward much better to make data long.tjebo
@Tjebo. My terse answer reflected the terseness of the question.Edward

1 Answers

0
votes

Use package lubridate for your dates. And make your data long. Many many threads here on SO on this topic.

library(tidyverse)
library(lubridate)
#devtools::install_github('alistaire47/read.so')

mydf <- read.so::read.so(' X    ARRIVAL    DELAY    PRECIP    DATDEP
  1    08:12      -10       0        01AUG2019
  2    11:22      120       19.2222  01AUG2019
  3    09:22      22        0.4444   01AUG2019
  4    21:22      0         33.2222  01AUG2019
  5    08:22      2         744.4444 02AUG2019') 

mydf <- mydf %>% pivot_longer(names_to = 'key', values_to = 'value', cols = DELAY:PRECIP)

ggplot(mydf, aes(dmy(DATDEP), value)) + geom_line(aes(color = key))

Created on 2020-03-20 by the reprex package (v0.3.0)