[R] How to plot dates

Avi Gross @v|gro@@ @end|ng |rom ver|zon@net
Wed Mar 17 01:59:27 CET 2021


Not sure what you mean by a horizontal line, Greg.

I change one of my plots to add a path between corresponding values of the
sequence variable but obviously those lines are mostly not horizontal. Look
at geom_path and similar geoms like geom_line to connect endpoints grouped
whatever way you specify.

ggplot(data=myDat,aes(x=date, y=time, label=time)) + 
  geom_point(aes(color=seq)) + 
  geom_path(aes(group=seq)) +
  geom_text(aes(color=seq))

As this is a help group, I think I am done.

From: Gregory Coats <mailto:gregcoats using me.com> 
Sent: Tuesday, March 16, 2021 8:26 PM
To: Avi Gross <mailto:avigross using verizon.net>
Cc: mailto:r-help using r-project.org
Subject: Re: [R] How to plot dates

Thank you very much.
In addition to what your did, for event 1, I would like to draw a horizontal
line connecting from day 1 to day 2 to day 3 to day 4.
Then, for event 2, I would like to draw a horizontal line connecting from
day 1 to day 2 to day 3 to day 4.
Similarly for events 3, and 4. Is that convenient to do?
Greg Coats

On Mar 16, 2021, at 8:01 PM, Avi Gross via R-help
<mailto:r-help using r-project.org> wrote:

Here is an example that worked for me doing roughly what I mentioned but
note my names changed. It makes two plots.

library (ggplot2)
myDat <- read.table(text =
                     "datetimeraw
2021-03-12 05:16:46
2021-03-12 09:17:02
2021-03-12 13:31:43
2021-03-12 22:00:32
2021-03-13 09:21:43
2021-03-13 13:51:12
2021-03-13 18:03:13
2021-03-13 22:20:28
2021-03-14 08:59:03
2021-03-14 13:15:56
2021-03-14 17:25:23
2021-03-14 21:36:26",
                   sep = ",", header = TRUE)
head(myDat)
myDat$datetime <- as.POSIXct(myDat$datetimeraw, tz = "", format ="%Y-%M-%d
%H:%M:%OS")
myDat$date <- factor(format(myDat$datetime, "%Y-%m-%d"))
myDat$time <- format(myDat$datetime, "%H:%M")
myDat$seq <- factor(rep(1:4, 3))

# just dots
ggplot(data=myDat,aes(x=date, y=time)) + geom_point(aes(color=seq))

# Also text
ggplot(data=myDat,aes(x=date, y=time, label=time)) + 
 geom_point(aes(color=seq)) + 
              geom_text(aes(color=seq))


From: Gregory Coats <gregcoats using me.com> 
Sent: Tuesday, March 16, 2021 8:26 PM
To: Avi Gross <avigross using verizon.net>
Cc: r-help using r-project.org
Subject: Re: [R] How to plot dates

Thank you very much.
In addition to what your did, for event 1, I would like to draw a horizontal
line connecting from day 1 to day 2 to day 3 to day 4.
Then, for event 2, I would like to draw a horizontal line connecting from
day 1 to day 2 to day 3 to day 4.
Similarly for events 3, and 4. Is that convenient to do?
Greg Coats


On Mar 16, 2021, at 8:01 PM, Avi Gross via R-help
<mailto:r-help using r-project.org> wrote:

Here is an example that worked for me doing roughly what I mentioned but
note my names changed. It makes two plots.

library (ggplot2)
myDat <- read.table(text =
                     "datetimeraw
2021-03-12 05:16:46
2021-03-12 09:17:02
2021-03-12 13:31:43
2021-03-12 22:00:32
2021-03-13 09:21:43
2021-03-13 13:51:12
2021-03-13 18:03:13
2021-03-13 22:20:28
2021-03-14 08:59:03
2021-03-14 13:15:56
2021-03-14 17:25:23
2021-03-14 21:36:26",
                   sep = ",", header = TRUE)
head(myDat)
myDat$datetime <- as.POSIXct(myDat$datetimeraw, tz = "", format ="%Y-%M-%d
%H:%M:%OS")
myDat$date <- factor(format(myDat$datetime, "%Y-%m-%d"))
myDat$time <- format(myDat$datetime, "%H:%M")
myDat$seq <- factor(rep(1:4, 3))

# just dots
ggplot(data=myDat,aes(x=date, y=time)) + geom_point(aes(color=seq))

# Also text
ggplot(data=myDat,aes(x=date, y=time, label=time)) + 
 geom_point(aes(color=seq)) + 
              geom_text(aes(color=seq))



More information about the R-help mailing list