Notes from Coursera EDA course

base plot
when use with in plotting, use {} on multi-line commands

data(cars)
with(cars,{
  plot(speed,dist)
  lines(loess.smooth(speed,dist))
  })

ggplot To copy plot to another device, after plotting, use dev.copy(filetype, filename) To change color scheme, could use #scale_fill_manual() or scale_colour_manual() for points/lines #scale_fill_brewer. note brewer has max 12 colors

library(ggplot2)
data(mpg)
qplot(displ,hwy,data=mpg,color=manufacturer)

dev.copy(png,file="mpg plot.png")
## quartz_off_screen 
##                 3
dev.off()
## quartz_off_screen 
##                 2
x<-rnorm(30)
y<-rnorm(30)
plot(x,y,col=rep(1:3,each=10),pch=19)
legend("bottomright",legend=paste("Group",1:3),col=1:3,pch=19,bty='n')

image(volcano, col = heat.colors(10), main = "heat.colors()")

image(volcano, col = topo.colors(10), main = "topo.colors()")

colorRamp and colorRampPalette interpolate the specified color

pal <- colorRamp(c("red", "blue"))

rgb() returns HEX value, default maxColorValue is 1

rgb(0, 0, 234, maxColorValue = 255)
## [1] "#0000EA"

Could use colorRampPalette to interpolate colorBrewer
Use brewer.pal(#ofcolor, “palette name”)
then colorRampPalette(#ofcolor needed in chart)

library(RColorBrewer)
display.brewer.all()

col<-brewer.pal(3,"YlGn")
pal <- colorRampPalette(col)
image(volcano, col = pal(20))

smoothScatter use RcolorBrewer and is good for visualize big dataset

set.seed(1)
x<-rnorm(10000)
y<-rnorm(10000)
smoothScatter(x,y)