library(ggplot2)
library(gridExtra)
data1 <- diamonds
detrend <- lm(log(price)~log(carat) ,data=data1)
data1$lprice2 <- resid(detrend)
empty <- ggplot()
empty <- empty + geom_point(aes(1,1), colour="white")
empty <- empty + theme(axis.ticks=element_blank(),
panel.background=element_blank(),
axis.text.x=element_blank(),
axis.text.y=element_blank(),
axis.title.x=element_blank(),
axis.title.y=element_blank(),
panel.grid=element_blank())
scatter <- qplot(log(carat), lprice2, data=data1,
xlab="Weight", ylab="Price Residuals",
colour=factor(color),
main="Diamonds - Weight to Price by Color")
scatter <- scatter + theme(legend.position="top")
scatter <- scatter + theme(plot.title=element_text(size=20, colour="blue"))
hist_left <- ggplot(data1,aes(x=price, fill=color))
hist_left <- hist_left + geom_histogram(aes(y = ..density..))
hist_left <- hist_left + labs(x=NULL, y=NULL, title=NULL)
hist_left <- hist_left + theme(legend.position = "none")
hist_bottom <- ggplot(data1, aes(x=carat, fill=color))
hist_bottom <- hist_bottom + geom_histogram()
hist_bottom <- hist_bottom + theme(legend.position = "none")
grid.arrange(arrangeGrob(hist_left + coord_flip(), scatter, ncol=2, widths=c(1,3)),
arrangeGrob(empty, hist_bottom, ncol=2, widths=c(1,3)),
heights=c(3,1))