Book Image

R Graphs Cookbook

By : Hrishi V. Mittal
Book Image

R Graphs Cookbook

By: Hrishi V. Mittal

Overview of this book

<p>With more than two million users worldwide, R is one of the most popular open source projects. It is a free and robust statistical programming environment with very powerful graphical capabilities. Analyzing and visualizing data with R is a necessary skill for anyone doing any kind of statistical analysis, and this book will help you do just that in the easiest and most efficient way possible.</p> <p>Unlike other books on R, this book takes a practical, hands-on approach and you dive straight into creating graphs in R right from the very first page.</p> <p>You want to harness the power of this open source programming language to visually present and analyze your data in the best way possible – and this book will show you how.</p> <p>The <em>R Graph Cookbook</em> takes a practical approach to teaching how to create effective and useful graphs using R. This practical guide begins by teaching you how to make basic graphs in R and progresses through subsequent dedicated chapters about each graph type in depth. It will demystify a lot of difficult and confusing R functions and parameters and enable you to construct and modify data graphics to suit your analysis, presentation, and publication needs.</p> <p>You will learn all about making graphics such as scatter plots, line graphs, bar charts, pie charts, dot plots, heat maps, histograms and box plots. In addition, there are detailed recipes on making various combinations and advanced versions of these graphs. Dedicated chapters on polishing and finalizing graphs will enable you to produce professional-quality graphs for presentation and publication. With R Graph Cookbook in hand, making graphs in R has never been easier.</p>
Table of Contents (16 chapters)
R Graphs Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface

Plotting data on Google maps


In this recipe, we will learn how to plot data on top of Google map images using a special package that connects to Google's Static Maps API.

Getting ready

First we need to install the RgoogleMaps package and a related package rgdal:

install.packages("rgdal")
library(rgdal)
install.packages("RgoogleMaps")
library(RgoogleMaps)

We will use the londonair.csv example dataset for this recipe. This dataset contains annual average concentrations of particulate matter in London's atmosphere measured at 12 different air quality monitoring sites across the city (data source: London air website http://www.londonair.org.uk). So let's load that too:

air<-read.csv("londonair.csv")

How to do it...

Let's pull a Google map of London city and plot the pollution data as points on top of it:

london<-GetMap(center=c(51.51,-0.116),
zoom =10, destfile = "London.png",maptype = "mobile")
PlotOnStaticMap(london,lat = air$lat, lon = air$lon,
cex=2,pch=19,col=as.character(air$color)...