# session 2 commands # first, read in the data; sal <- read.table("salary.dat", header=TRUE) # Q1 - some plots of variables (of different types) plot(year~salary, data=sal) plot(salary~year, data=sal) plot(salary~jitter(year), data=sal) plot(salary~rank, data=sal) plot(field~rank, data=sal) plot(salary~gender, data=sal) # Q2 #conditioning plot; can year explain the M/F difference? library(lattice) bwplot(salary~gender|year,data=sal) #can rank explain it? (yes, mostly) plot(salary~interaction(gender,rank), data=sal) # Q4 library(MASS) search() plot(brain~body,mammals) plot(brain~body,mammals,log="xy") # get x and y co-ordinates for wherever you click locator() # add text to points you click near # (right click to stop it) identify(mammals$body,mammals$brain,labels=row.names(mammals)) plot(brain~body,mammals,log="xy") with(mammals, lines(lowess(body,brain), col="red")) plot(log(brain)~log(body), mammals) with(mammals, lines(lowess(log(body),log(brain)), col="red"))