Install and load the ggplot2 and plyr packages.
install.packages("ggplot2", dependencies = TRUE)
Error: trying to use CRAN without setting a mirror
##install.packages("grid")
library(ggplot2)
library(plyr)
library(lattice)
library(hexbin)
gdURL <- "http://www.stat.ubc.ca/~jenny/notOcto/STAT545A/examples/gapminder/data/gapminderDataFiveYear.txt"
gDat <- read.delim(file = gdURL)
gDat <- droplevels(subset(gDat, continent!="Oceania"))
p <- ggplot(gDat, aes(x = year, y = lifeExp))
p+ geom_point(alpha = 0.4) + geom_smooth(colour="red") ##smooth uses "mean"?
stat_sum_single <- function(fun, geom="point", ...) {
stat_summary(fun.y=fun, geom="smooth", size = 1, ...)
}
myTrimMean = function (x){
mean(x,tirm=0.1)
}
ggplot(gDat, aes(x = year, y = lifeExp,color=factor(continent)))+ geom_point(alpha=0.6)+ stat_sum_single(myTrimMean)+facet_wrap(~continent)
ggplot(gDat, aes(x = gdpPercap, y = lifeExp,color=factor(continent)))+ scale_x_log10()+ geom_point(alpha = 0.6) + geom_smooth(se = FALSE) #confidence band off
ggplot(gDat, aes(x = gdpPercap, y = lifeExp))+ scale_x_log10()+ geom_hex() + geom_smooth(se = FALSE)+facet_wrap(~continent)
hexbinplot(lifeExp ~ gdpPercap|continent, gDat,scales = list(x = list(log = 10)),xbins = 40)
ggplot(gDat, aes(x = gdpPercap, y = lifeExp,color=factor(continent)))+geom_point(alpha=0.3)+scale_x_log10() + geom_smooth(method=loess,se = FALSE)+ facet_grid(continent~year)
ggplot(gDat, aes(x = gdpPercap,color=factor(continent)))+geom_density()+scale_x_log10()
densityplot(~gdpPercap, data =gDat,scales = list(x = list(log = 10)),plot.points=FALSE,ref=TRUE, groups = reorder(continent, gdpPercap), auto.key = TRUE)
bMark = 48.20
proLoLifeExp <- ddply(gDat, ~ continent + year, function(x)
{jCount = sum(x$lifeExp <= bMark)
c(count = jCount, prop = jCount / nrow(x)) })
ggplot(proLoLifeExp, aes(x=year,y=prop,color=factor(continent)))+geom_smooth(method=loess,se=FALSE)
xyplot (prop ~ year, group=continent,proLoLifeExp, jitter.data = TRUE,auto.key = TRUE, grid = "h",type="l")