This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
library(RCurl)
## Warning: package 'RCurl' was built under R version 3.1.2
## Loading required package: bitops
## Warning: package 'bitops' was built under R version 3.1.2
options(RCurlOptions = list(cainfo = system.file("CurlSSL", "cacert.pem", package = "Rcurl")))
#credentials$handshake()
library(ggplot2)
p<-ggplot(mtcars,aes(wt, mpg))+geom_point(aes(color=factor(cyl)),size=4)
p+labs(title="Regression of MPG on Weight",x="Car Weight",y="Miles Per Gallon")
#Regression of MPG on Weight
p<-ggplot(mtcars,aes(wt, mpg))+geom_point(aes(color=factor(cyl)),size=4)+stat_smooth(method="lm",size=1,colour="black")
p+labs(title="Regression of MPG on Weight",x="Car Weight",y="Miles Per Gallon")
# Filled Density Plot
p<-ggplot(mtcars,aes(x=mpg))+geom_density(fill="red",size=0.5,alpha=0.3)
p+labs(title="Kernel Density of Miles Per Gallon",x="Miles Per Gallon",y="density")
#pairs plot
library(GGally)
## Warning: package 'GGally' was built under R version 3.1.2
sub<-subset(mtcars, select=c("mpg","disp","drat","wt"))
ggpairs(sub, alpha=0.4,title="Simple Scatterplot Matrix")
p<-ggplot(mtcars,aes(wt, mpg))+geom_point(aes(color=factor(cyl)),size=4)+stat_smooth(method="loess",size=1,colour="blue")+stat_smooth(method="lm",size=1,colour="black")
#p+geom_line(lowess(wt,mpg),color="blue")
p+labs(title="Regression of MPG on Weight With loess",x="Car Weight",y="Miles Per Gallon")
library(scatterplot3d)
## Warning: package 'scatterplot3d' was built under R version 3.1.2
with(mtcars, {
s3d <- scatterplot3d(wt, disp, mpg, # x y and z axis
color="blue", pch=19, # filled blue circles
type="h", # vertical lines to the x-y plane
main="3-D Scatterplot in mtcars",
zlab="Displacement (cu. in.)",
xlab="Weight (lb/1000)",
ylab="Miles/(US) Gallon")
s3d.coords <- s3d$xyz.convert(wt, disp, mpg) # convert 3D coords to 2D projection
text(s3d.coords$x, s3d.coords$y, # x and y coordinates
labels=row.names(mtcars), # text to plot
cex=.5, pos=4) # shrink text 50% and place to right of points)
})
Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.