#Problem 1: Solution sales1<-c(12,14,16,29,30,45,19,20,16, 19, 34, 20) sales2<-rpois(12,34) # random numbers, Poisson distribution, mean at 34, 12 numbers par(bg="cornsilk") plot(sales1, col="blue", type="o", ylim=c(0,100), xlab="Month", ylab="Sales" ) title(main="Sales by Month") lines(sales2, type="o", pch=22, lty=2, col="red") grid(nx=NA, ny=NULL) legend("topright", inset=.05, c("Sales1","Sales2"), fill=c("blue","red"), horiz=TRUE) #Problem 2: Solution sales<-read.table(file.choose(), header=T) sales # to verify that data has been read barplot(as.matrix(sales), main="Sales Data", ylab= "Total",beside=T, col=rainbow(5)) #Problem 3: Solution fn<-boxplot(sales,col=c("orange","green"))$stats text(1.45, fn[3,2], paste("Median =", fn[3,2]), adj=0, cex=.7) text(0.45, fn[3,1],paste("Median =", fn[3,1]), adj=0, cex=.7) grid(nx=NA, ny=NULL) #Problem 4: Access web files fb1<-read.csv("http://real-chart.finance.yahoo.com/table.csv?s=FB&d=10&e=5&f=2014&g=d&a=11&b=12&c=2013&ignore=.csv") View(fb1) par(bg="cornsilk") #Problem 5: Access existing data sets in R data() #Observe the data sets available for explorations. attach(mpg) head(mpg) summary(mpg) #after analysis remove the data from the memory detach(mpg) library (help=datasets #Problem 6: External APIs and "map" library("ggmap") library("maptools") library(maps) visited <- c("SFO", "Chennai", "London", "Melbourne", "Johannesbury, SA") ll.visited <- geocode(visited) visit.x <- ll.visited$lon visit.y <- ll.visited$lat map("world", fill=TRUE, col="white", bg="lightblue", ylim=c(-60, 90), mar=c(0,0,0,0)) points(visit.x,visit.y, col="red", pch=36) #USA map library("ggmap") library("maptools") library(maps) visited <- c("SFO", "New York", "Buffalo", "Dallas, TX") ll.visited <- geocode(visited) visit.x <- ll.visited$lon visit.y <- ll.visited$lat map("state", fill=TRUE, col=rainbow(50), bg="lightblue", mar=c(0,0,0,0)) points(visit.x,visit.y, col="yellow", pch=36) #Problem 7: Lattice splom(mtcars[c(1,3,4,5,6)], main="MTCARS Data") splom(mtcars[c(1,3,4,6)], main="MTCARS Data") splom(mtcars[c(1,3,4,6)], col=rainbow(),main="MTCARS Data") Another data set: “rock” splom(rock[c(1,2,3,4)], main="ROCK Data")