Graphics
Use custom tick labels for an axis of a plot
myBinLabels <- c("0-10","11-20","21-30","31-40","41-50","51-60")
plot(mean.v2eff, ylim=c(80,100), xaxt="n")
axis(side=1, at=c(1:6), labels=myBinLabels)
Generate a sequence of dates and use that vector as axis labels on a plot
myaxis.days <- seq(as.Date("2006/1/1"), as.Date("2007/12/31"), "days")
# to convert it to a certain format
myaxis.months <- format(myaxis.days, "%b %y")
# in the axis command, las=2 turns labels perpendicular to the axis
axis.Date(1, at=myaxis.months, format="%b %y", las=2)
Dynamically interact with a plot to label outlier dates
First set up a plot.
plot(result.df$APO_ARREFF, result.df$V2EFF)
Call the identify function on the plot with a vector of labels. Clicking on a data point adds a label, the function returns the index of point selected.
identify(result.df$APO_ARREFF, result.df$V2EFF, labels=label.dates)
Save a chart straight from script rather than manually through GUI
jpeg(file="myChart.jpeg", width=800, height=400, quality=100)
plot(xVariable, yVariable, main="My Chart")
dev.off()
# load the library
library(RODBC)
# open the connection, assuming you have an ODBC setup, call the DSN here
# this will prompt you for user id, password, and you can switch to a different TNS service name as well
mychannel <- odbcConnect("crs")
# enter the query and save the result in a data frame in R for further processing later
result.df <- sqlQuery(mychannel, "select * from bhogan.npiasairports where state='NY'")
# close the ODBC connection
close(mychannel)
result.df <- sqlQuery(mychannel,
paste("select *",
"from bhogan.derived_aspm_slots A",
"where",
"A.slice_start_loc>=to_date('20070817 08','yyyymmdd hh24') and",
"A.slice_start_loc<to_date('20070818 01','yyyymmdd hh24') and",
"A.locid='EWR'",
"and A.latest='T'",
"order by A.yyyymm, A.dday, A.hhour, A.qtr"))