[R] How to plot dates

Gregory Coats gregco@t@ @end|ng |rom me@com
Tue Mar 16 23:32:23 CET 2021


Thank you. Let me redefine the situation.
Each time an event starts, I record the date and time.
Each day there are 4 new events. Time is the only variable.
I would like to graphically show how the time for events 1, 2, 3, and 4 for the current day compare to the times for events 1, 2, 3, and 4 for the previous day. How would I plot / display those times differences?
Greg Coats

library (ggplot2)
myDat <- read.table(text =
"datetime
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$datetime, tz = "", format ="%Y-%M-%d %H:%M:%OS")

> On Mar 16, 2021, at 3:34 PM, John Fox <jfox using mcmaster.ca> wrote:
> 
> Dear Greg,
> 
> Coordinate plots typically have a horizontal (x) and vertical (y) axis. The command
> 
> 	ggplot(myDat, aes(x=datetime, y = datetime)) + geom_point()
> 
> works, but I doubt that it produces what you want.
> 
> You have only one variable in your data set -- datetime -- so it's not obvious what you want to do. If you can't clearly describe the structure of the plot you intend to draw, it's doubtful that I or anyone else can help you.
> 
> Best,
> John
> 
> John Fox, Professor Emeritus
> McMaster University
> Hamilton, Ontario, Canada
> web: https://socialsciences.mcmaster.ca/jfox/ <https://socialsciences.mcmaster.ca/jfox/>

	[[alternative HTML version deleted]]



More information about the R-help mailing list