[R] Print date on y axis with month, day, and year
Sorkin, John
j@ork|n @end|ng |rom @om@um@ry|@nd@edu
Fri May 10 01:58:32 CEST 2024
I am trying to use ggplot to plot the data, and R code, below. The dates (jdate) are printing as Mar 01, Mar 15, etc. I want to have the date printed as MMM DD YYYY (or any other way that will show month, date, and year, e.g. mm/dd/yy). How can I accomplish this?
yyy <- structure(list(
jdate = structure(c(19052, 19053, 19054, 19055,
19058, 19059, 19060, 19061, 19062, 19063, 19065, 19066, 19067,
19068, 19069, 19072, 19073, 19074, 19075, 19076, 19077, 19083,
19086, 19087, 19088, 19089, 19090, 19093, 19094, 19095), class = "Date"),
Sum = c ( 1, 3, 9, 11, 13, 16, 18, 22, 26, 27, 30, 32, 35, 39, 41,
43, 48, 51, 56, 58, 59, 63, 73, 79, 81, 88, 91, 93, 96, 103)),
row.names = c(NA, 30L), class = "data.frame")
yyy
class(yyy$jdate)
ggplot(data=yyy[1:30,],aes(as.Date(jdate,format="%m-%d-%Y"),Sum)) +geom_point()
Thank you
John
John David Sorkin M.D., Ph.D.
Professor of Medicine, University of Maryland School of Medicine;
Associate Director for Biostatistics and Informatics, Baltimore VA Medical Center Geriatrics Research, Education, and Clinical Center;
PI Biostatistics and Informatics Core, University of Maryland School of Medicine Claude D. Pepper Older Americans Independence Center;
Senior Statistician University of Maryland Center for Vascular Research;
Division of Gerontology and Paliative Care,
10 North Greene Street
GRECC (BT/18/GR)
Baltimore, MD 21201-1524
Cell phone 443-418-5382
More information about the R-help
mailing list