Advertisement
tomsim

Plot data with date time axis

Aug 17th, 2015
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 0.97 KB | None | 0 0
  1. # Get subset data
  2. plotData = subset(plotData, SITE_COUNT == siteFilter)
  3. # Convert date text field into date data type (example input data date format is YYYY-MM-DD)
  4. plotData$useDate <- as.Date(as.character(plotData$useDate),format="%Y-%m-%d")
  5. # Compute date range to use in plot
  6. dateRange = c(min(plotData$useDate, na.rm=TRUE), max(plotData$useDate, na.rm=TRUE))
  7. # Pick data to plot
  8. grpName = "T01J750"
  9. py = plotData$testerHour[plotData$testerName == grpName]
  10. py5 = plotData$testerHour512[plotData$testerName == grpName]
  11. px = plotData$useDate[plotData$testerName == grpName]
  12. # plot x,y data
  13. plot( px, py, xlim=dateRange, ylim=yRange, main=plotTitle, type="h", lwd=3, ylab="Used Hours", xlab="", col="blue", xaxt="n")
  14. # Setup plot engine to overlay next plot (else it will create a new plot)
  15. par(new=T)
  16. plot( px, py5, xlim=dateRange, ylim=yRange, type="h", lwd=3, col="red", xaxt="n", ylab="")
  17. axis.Date(1, at=seq(dateRange[1], dateRange[2], by="day"), format="%a %d-%m", las=2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement