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

Creating and reading KML data


In this recipe, we will learn how to read and write geographic data in Google's Keyhole Markup Language (KML) format, which can be used to visualize geographic data with Google Earth and Google Maps.

Getting ready

We will use the rgdal package in this recipe. So let's make sure it's installed and load it:

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

How to do it...

We will use data from the cities shapefile that's installed as part of the rgdal package. First we will write a KML file and then read it:

cities <- readOGR(system.file("vectors",
package = "rgdal")[1],"cities")
writeOGR(cities, "cities.kml", "cities", driver="KML")
df <- readOGR("cities.kml", "cities")

How it works...

In the preceding example, we first used the readOGR() function to read the cities shapefile dataset. The first argument is the folder (directory) where the data shapefile is and the second argument is the name of the shapefile (without the .shp extension). We stored the object returned...