This report is automatically generated with the R package knitr (version 1.5) .

# Chapter 18 - Looking At ggplot2 Graphics Installing and Loading ggplot2
install.packages("ggplot2")
## Installing package into 'C:/Users/Andrie/Documents/R/win-library/3.0'
## (as 'lib' is unspecified)
## Warning in install.packages :
##   package 'ggplot2' is in use and will not be installed
library("ggplot2")
# Looking At Layers
ggplot(faithful, aes(x = eruptions, y = waiting)) + geom_point() + stat_smooth()
## geom_smooth: method="auto" and size of largest group is <1000, so using loess. Use 'method = x' to change the smoothing method.
plot of chunk unnamed-chunk-1
# Using Geoms and Stats Defining what data to use Mapping data to plot aesthetics
ggplot(faithful, aes(x = eruptions, y = waiting)) + geom_point() + stat_smooth()
## geom_smooth: method="auto" and size of largest group is <1000, so using loess. Use 'method = x' to change the smoothing method.
plot of chunk unnamed-chunk-1
## Getting geoms Creating a bar chart
ggplot(quakes, aes(x = depth)) + geom_bar()
## stat_bin: binwidth defaulted to range/30. Use 'binwidth = x' to adjust this.
plot of chunk unnamed-chunk-1
ggplot(quakes, aes(x = depth)) + geom_bar(binwidth = 50)
plot of chunk unnamed-chunk-1
quakes.agg <- aggregate(mag ~ round(depth, -1), data = quakes, FUN = length)
names(quakes.agg) <- c("depth", "mag")
ggplot(quakes.agg, aes(x = depth, y = mag)) + geom_bar(stat = "identity")
plot of chunk unnamed-chunk-1
### Making a scatterplot
ggplot(quakes, aes(x = long, y = lat)) + geom_point()
plot of chunk unnamed-chunk-1
### Creating line charts
ggplot(longley, aes(x = Year, y = Unemployed)) + geom_line()
plot of chunk unnamed-chunk-1
# Sussing Stats Binning data
ggplot(quakes, aes(x = depth)) + geom_bar(binwidth = 50)
plot of chunk unnamed-chunk-1
ggplot(quakes, aes(x = depth)) + stat_bin(binwidth = 50)
plot of chunk unnamed-chunk-1
## Smoothing data
ggplot(longley, aes(x = Year, y = Employed)) + geom_point()
plot of chunk unnamed-chunk-1
ggplot(longley, aes(x = Year, y = Employed)) + geom_point() + stat_smooth()
## geom_smooth: method="auto" and size of largest group is <1000, so using loess. Use 'method = x' to change the smoothing method.
plot of chunk unnamed-chunk-1
ggplot(longley, aes(x = Year, y = Employed)) + geom_point() + stat_smooth(method = "lm")
plot of chunk unnamed-chunk-1
# Adding Facets, Scales, and Options Adding facets
ggplot(mtcars, aes(x = hp, y = mpg)) + geom_point()
plot of chunk unnamed-chunk-1
ggplot(mtcars, aes(x = hp, y = mpg)) + geom_point() + stat_smooth(method = "lm") + facet_grid(~cyl)
plot of chunk unnamed-chunk-1
ggplot(mtcars, aes(x = hp, y = mpg)) + geom_point(aes(shape = factor(cyl), colour = factor(cyl)))
plot of chunk unnamed-chunk-1
ggplot(mtcars, aes(x = hp, y = mpg)) + geom_point(aes(shape = factor(cyl), colour = factor(cyl))) +
    scale_shape_discrete(name = "Cylinders") + scale_colour_discrete(name = "Cylinders")
plot of chunk unnamed-chunk-1
## Changing options
ggplot(mtcars, aes(x = hp, y = mpg)) + geom_point(color = "red") + xlab("Performance (horse power") +
    ylab("Fuel consumption (mpg)") + opts(title = "Motor car comparison")
## 'opts' is deprecated. Use 'theme' instead. (Deprecated; last used in version 0.9.1)
## Setting the plot title with opts(title="...") is deprecated.
##  Use labs(title="...") or ggtitle("...") instead. (Deprecated; last used in version 0.9.1)
plot of chunk unnamed-chunk-1

The R session information (including the OS info, R version and all packages used):

sessionInfo()
## R version 3.0.2 (2013-09-25)
## Platform: x86_64-w64-mingw32/x64 (64-bit)
## 
## locale:
## [1] LC_COLLATE=English_United Kingdom.1252  LC_CTYPE=English_United Kingdom.1252   
## [3] LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C                           
## [5] LC_TIME=English_United Kingdom.1252    
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
##  [1] BiocInstaller_1.12.1 ggplot2_0.9.3.1      reshape2_1.2.2       sos_1.3-8           
##  [5] brew_1.0-6           stringr_0.6.2        knitr_1.5            plyr_1.8            
##  [9] Revobase_7.1.0       RevoMods_7.1.0       RevoScaleR_7.1.0     lattice_0.20-27     
## [13] rpart_4.1-2         
## 
## loaded via a namespace (and not attached):
##  [1] codetools_0.2-8    colorspace_1.2-4   dichromat_2.0-0    digest_0.6.4      
##  [5] evaluate_0.5.1     foreach_1.4.1      formatR_0.10       fortunes_1.5-2    
##  [9] grid_3.0.2         gtable_0.1.2       highr_0.3          iterators_1.0.6   
## [13] labeling_0.2       MASS_7.3-29        munsell_0.4.2      proto_0.3-10      
## [17] RColorBrewer_1.0-5 scales_0.2.3       tools_3.0.2
Sys.time()
## [1] "2014-05-13 15:06:45 BST"