R Data Visualization Cookbook - Atmajitsinh Gohil - E-Book

R Data Visualization Cookbook E-Book

Atmajitsinh Gohil

0,0
34,79 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

If you are a data journalist, academician, student or freelance designer who wants to learn about data visualization, this book is for you. Basic knowledge of R programming is expected.

Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:

EPUB
MOBI

Seitenzahl: 281

Veröffentlichungsjahr: 2015

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Table of Contents

R Data Visualization Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers, and more
Why Subscribe?
Free Access for Packt account holders
Preface
What this book covers
What you need for this book
Who this book is for
Sections
Getting ready
How to do it…
How it works…
There's more…
See also
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. A Simple Guide to R
Installing packages and getting help in R
Getting ready
How to do it…
How it works…
There's more…
See also
Data types in R
How to do it…
Special values in R
How to do it…
How it works…
Matrices in R
How to do it…
How it works…
Editing a matrix in R
How to do it…
Data frames in R
How to do it…
Editing a data frame in R
How to do it...
Importing data in R
How to do it...
How it works…
Exporting data in R
How to do it…
How it works…
Writing a function in R
Getting ready
How to do it…
How it works…
See also
Writing if else statements in R
How to do it…
How it works…
Basic loops in R
How to do it…
How it works…
Nested loops in R
How to do it…
The apply, lapply, sapply, and tapply functions
How to do it…
How it works…
Using par to beautify a plot in R
How to do it…
How it works…
Saving plots
How to do it…
How it works…
2. Basic and Interactive Plots
Introduction
Introducing a scatter plot
Getting ready
How to do it…
How it works…
Scatter plots with texts, labels, and lines
How to do it…
How it works…
There's more…
See also
Connecting points in a scatter plot
How to do it…
How it works…
There's more…
See also
Generating an interactive scatter plot
Getting ready
How to do it…
How it works…
There's more…
See also
A simple bar plot
How to do it…
How it works…
There's more…
See also
An interactive bar plot
Getting ready
How to do it…
How it works…
There's more…
See also
A simple line plot
Getting ready
How to do it…
How it works…
See also
Line plot to tell an effective story
Getting ready
How to do it…
How it works…
See also
Generating an interactive Gantt/timeline chart in R
Getting ready
How to do it…
See also
Merging histograms
How to do it…
How it works…
Making an interactive bubble plot
How to do it…
How it works…
There's more…
See also
Constructing a waterfall plot in R
Getting ready
How to do it…
3. Heat Maps and Dendrograms
Introduction
Constructing a simple dendrogram
Getting ready
How to do it…
How it works…
There's more...
See also
Creating dendrograms with colors and labels
Getting ready
How to do it…
How it works…
There's more…
Creating a heat map
Getting ready
How to do it…
How it works…
There's more…
See also
Generating a heat map with customized colors
Getting ready
How to do it…
How it works…
Generating an integrated dendrogram and a heat map
How to do it…
There's more…
See also
Creating a three-dimensional heat map and a stereo map
Getting ready
How to do it…
See also
Constructing a tree map in R
Getting ready
How to do it…
How it works…
There's more…
See also
4. Maps
Introduction
Introducing regional maps
Getting ready
How to do it…
How it works…
See also
Introducing choropleth maps
Getting ready
How to do it…
How it works…
There's more…
See also
A guide to contour maps
How to do it…
How it works…
There's more…
See also
Constructing maps with bubbles
Getting ready
How to do it…
How it works...
There's more…
See also
Integrating text with maps
Getting ready
How to do it…
See also
Introducing shapefiles
Getting ready
How to do it…
See also
Creating cartograms
Getting ready
How to do it…
See also
5. The Pie Chart and Its Alternatives
Introduction
Generating a simple pie chart
How to do it…
How it works…
There's more...
See also
Constructing pie charts with labels
Getting ready
How to do it…
How it works…
There's more…
Creating donut plots and interactive plots
Getting rady
How to do it...
How it works…
There's more…
See also
Generating a slope chart
Getting ready
How to do it…
How it works…
See also
Constructing a fan plot
Getting ready
How to do it…
How it works…
6. Adding the Third Dimension
Introduction
Constructing a 3D scatter plot
Getting ready
How to do it…
How it works…
There's more…
See also
Generating a 3D scatter plot with text
Getting ready
How to do it…
How it works…
There's more…
See also
A simple 3D pie chart
Getting ready
How to do it…
How it works…
A simple 3D histogram
Getting ready
How to do it…
How it works…
There's more...
Generating a 3D contour plot
Getting ready
How to do it…
How it works…
Integrating a 3D contour and a surface plot
Getting ready
How to do it…
How it works…
There's more...
See also
Animating a 3D surface plot
Getting ready
How to do it…
How it works…
There's more…
See also
7. Data in Higher Dimensions
Introduction
Constructing a sunflower plot
Getting ready
How to do it…
How it works…
See also
Creating a hexbin plot
Getting ready
How to do it…
How it works…
See also
Generating interactive calendar maps
Getting ready
How to do it…
How it works…
See also
Creating Chernoff faces in R
Getting ready
How to do it…
How it works…
Constructing a coxcomb plot in R
Getting ready
How to do it…
How it works…
See also
Constructing network plots
Getting ready
How to do it…
How it works…
There's more…
See also
Constructing a radial plot
Getting ready
How to do it…
How it works…
There's more…
See also
Generating a very basic pyramid plot
Getting ready
How to do it…
How it works…
See also
8. Visualizing Continuous Data
Introduction
Generating a candlestick plot
Getting ready
How to do it…
How it works…
There's more…
See also
Generating interactive candlestick plots
Getting ready
How to do it…
How it works…
Generating a decomposed time series
How to do it…
How it works…
There's more…
See also
Plotting a regression line
How to do it…
How it works…
See also
Constructing a box and whiskers plot
Getting ready
How to do it…
How it works…
See also
Generating a violin plot
Getting ready
How to do it…
Generating a quantile-quantile plot (QQ plot)
Getting ready
How to do it…
See also
Generating a density plot
Getting ready
How to do it…
How it works…
There's more…
See also
Generating a simple correlation plot
Getting ready
How to do it…
How it works…
There's more…
See also
9. Visualizing Text and XKCD-style Plots
Introduction
Generating a word cloud
Getting ready
How to do it…
How it works…
There's more…
See also
Constructing a word cloud from a document
Getting ready
How to do it…
How it works…
There's more…
See also
Generating a comparison cloud
Getting ready
How to do it…
How it works…
See also
Constructing a correlation plot and a phrase tree
Getting ready
How to do it…
How it works…
There's more…
See also
Generating plots with custom fonts
Getting ready
How to do it…
How it works…
See also
Generating an XKCD-style plot
Getting ready
How to do it…
See also
10. Creating Applications in R
Introduction
Creating animated plots in R
Getting ready
How to do it…
How it works…
Creating a presentation in R
Getting ready
How to do it…
How it works…
There's more…
See also
A basic introduction to API and XML
Getting ready
How to do it…
How it works…
See also
Constructing a bar plot using XML in R
Getting ready
How to do it…
How it works…
See also
Creating a very simple shiny app in R
Getting ready
How to do it…
How it works…
See also
Index

R Data Visualization Cookbook

R Data Visualization Cookbook

Copyright © 2015 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

First published: January 2015

Production reference: 1240115

Published by Packt Publishing Ltd.

Livery Place

35 Livery Street

Birmingham B3 2PB, UK.

ISBN 978-1-78398-950-8

www.packtpub.com

Credits

Author

Atmajitsinh Gohil

Reviewers

Sharan Kumar Ravindran

Kannan Kalidasan

Erik M. Rodríguez Pacheco

Arun Padmanabhan

Juan Pablo Zamora

Patric Zhao

Commissioning Editor

Kartikey Pandey

Acquisition Editor

Neha Nagwekar

Content Development Editor

Arun Nadar

Technical Editors

Rohit Kumar Singh

Mitali Somaiya

Copy Editors

Nithya P

Shambhavi Pai

Rashmi Sawant

Project Coordinator

Neha Bhatnagar

Proofreaders

Simran Bhogal

Stephen Copestake

Paul Hindle

Joanna McMahon

Indexer

Priya Sane

Graphics

Disha Haria

Abhinash Sahu

Production Coordinator

Nilesh R. Mohite

Cover Work

Nilesh R. Mohite

About the Author

Atmajitsinh Gohil works as a senior consultant at a consultancy firm in New York City. After graduating, he worked in the financial industry as a Fixed Income Analyst. He writes about data manipulation, data exploration, visualization, and basic R plotting functions on his blog at http://datavisualizationineconomics.blogspot.com.

He has a master's degree in financial economics from the State University of New York (SUNY), Buffalo. He also graduated with a master of arts degree in economics from University of Pune, India. He loves to read blogs on data visualization and loves to go out on hikes in his free time.

This book would not have been possible without the help from numerous data visualizers and data scientists around the globe who bring into existence new and innovative ways to transform data into beautiful stories. I would like to sincerely thank the developers of R and R packages who have contributed so generously to the growing R open source community.

I would like to thank Jer Thorpe and Hans Rosling for their inspiring Ted videos on data visualization.

I would also like to thank all the economists and statisticians who have so often inspired me.

I would like to thank my publisher, Packt Publishing, for giving me the opportunity to work on this book. I would also like to thank all the technical reviewers and content development editors at Packt Publishing for their informative comments and suggestions.

Finally, I would like to thank my amazing family and magnificent friends for always encouraging and supporting me.

About the Reviewers

Sharan Kumar Ravindran is a lead data scientist in the fastest growing big data start-up based in Bangalore. His primary interests lie in statistics and machine learning. He has over 4 years of experience and has worked in the domains of e-commerce and IoT.

He has solved several problems on Kaggle and is among the top 10 percent of experts on Kaggle. His blog and social profiles can be found at www.rsharankumar.com.

He works for Flutura, which is ranked among the top 20 most promising big data companies across the globe by the leading analyst magazine, CIO Review. Flutura also featured on Gigaom reports on big data and M2M in the energy sector. Flutura was also the winner at TechSparks, where 800 innovative start-ups were evaluated.

Kannan Kalidasan is a software developer by profession, an autodidact, and open source evangelist. He has a decade's experience in database computing, data management, open source, and distributed computing. He holds a bachelor's of technology degree in computer science from Pondicherry University. He has played different roles in his career, such as a developer, an architect, a team lead, and a DBA. He currently holds the position of a BI Engineer at Orbitz Worldwide.

He started his own start-up back in 2005 on a part-time basis during his college days, worked with other companies in different open source projects, and provided training. He is passionate about technology and an entrepreneur at heart, and he likes to mentor fellow enthusiasts. His inherent curiosity keeps him occupied with learning new technologies and trying new things. He always believes that "our dreams can be delayed but will never fail if we work hard."

He blogs at www.kannandreams.wordpress.com and you can follow him on Twitter at @kannanpoem. He loves to take long walks alone, write Tamil poems, paint, and read books.

A big thank you to all who believed in me and supported me. I would like to thank my strong soul for pushing me to achieve my dreams. I would like to express my deepest gratitude to Packt Publishing for giving me this opportunity.

Erik M. Rodríguez Pacheco works as a manager in the Business Intelligence Unit at Banco Improsa in San José, Costa Rica. He has 11 years of experience in the financial industry. He is currently a professor of the Business Intelligence Specialization Program at the Instituto Tecnológico de Costa Rica's Continuing Education Program. Erik is an enthusiast of new technologies, particularly those related to business intelligence, data mining, and data science. He holds a Bachelor's degree in business administration from Universidad de Costa Rica, and has specialized in business intelligence from the Instituto Tecnológico de Costa Rica, data mining from Promidat (Programa Iberoamericano de Formación en Minería de Datos), and business intelligence and data mining from Universidad del Bosque, Colombia. He is currently enrolled in a specialization program in data science from Johns Hopkins University. He can be reached at cr.linkedin.com/in/erikrodriguez.

Arun Padmanabhan has about 4 years of experience in developing products including mobile, enterprise, statistical, and data mining applications. He graduated with a master's degree in computer applications in 2010. Currently, he is a data scientist at Flutura Decision Science and Analytics, where he is working at saving the world, one data product at a time.

Juan Pablo Zamora holds a bachelor's degree in statistics from the University of Costa Rica (UCR) in 2007. He is currently working on his dissertation in the field of predictive analytics and will obtain an MSc degree in statistics from the University of Costa Rica.

He enjoys teaching and was a tutor of statistics courses at the Business School of UNED of Costa Rica during 2010-2012. He also mentored others in the areas of data processing and analytics as well as the use of statistical analysis tools, to name a few.

Juan has over 7 years of experience in the banking industry, primarily in the credit card business for Central America and Mexico. He began as an analyst, eventually becoming the leader of a team of analysts for Central America's largest credit card issuer and acquirer. During this period, he participated in several predictive analytics projects related to credit risk, account retention, and profitability.

Juan recently joined a large multinational company in the retail sector with the task of building an analytics program to identify and prevent high-risk issues and/or threats to the business in Latin America.

His current interests are R, data visualization, business intelligence, predictive modeling, and big data. He can be reached at cr.linkedin.com/in/datasciencezamora or data.<[email protected]>.

Patric Zhao is a senior GPU architect in the High Performance Computing (HPC) field at Nvidia. He has experience in developing scientific and engineering applications and focuses on parallelization, performance modeling, and architecture-specific tuning. Patric is currently working on big data and machine learning areas, including regression, neural network, recommending system design, and implementation in CPU and GPU architectures. Patric has also contributed to accelerate R's applications by CUDA in the GPU ecosystem. You can find related articles on Nvidia's blog at http://devblogs.nvidia.com/parallelforall/author/patricz/ or write to him at <[email protected]>.

I would like to really thank my wife Yan Li J for always supporting and encouraging me.

www.PacktPub.com

Support files, eBooks, discount offers, and more

For support files and downloads related to your book, please visit www.PacktPub.com.

Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at <[email protected]> for more details.

At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.

https://www2.packtpub.com/books/subscription/packtlib

Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can search, access, and read Packt's entire library of books.

Why Subscribe?

Fully searchable across every book published by PacktCopy and paste, print, and bookmark contentOn demand and accessible via a web browser

Free Access for Packt account holders

If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view 9 entirely free books. Simply use your login credentials for immediate access.

Preface

Our ability to generate data has improved tremendously with the advent of technology. The data generated has become more complex with the passage of time. The complexity in data forces us to develop new tools and methods to analyze it, interpret it, and communicate with the data. Data visualization empowers us with the necessary skills required to convey the meaning of underlying data. Data visualization is a remarkable intersection of data, science, and art, and this makes it hard to define visualization in a formal way; a simple Google search will prove me right. The Merriam-Webster dictionary defines visualization as "formation of mental visual images". In reality, the term visualization goes beyond the limits of providing visual images by assisting humans in data recording, revealing pattern, exploration of data, and spreading information in a meaningful way.

Jer Thorpe in an interview with Mashable.com (http://mashable.com/2012/12/11/data-visualization-jer-thorp/) introduces the idea of humanizing data:

"…And I think that there's a huge possibility for humans, society as a whole—if we could share that data more usefully, for science and for the construction of cities, and for all these kinds of things, then it becomes much more useful. So in my work, I'm really thinking about how we can give people glimpses into that type of future. Giving people an opportunity to think about data ownership or giving people a visualization so that they can see the kinds of things that can be done with data".

R is an open source platform used to analyze data. It has been widely used as a statistical tool in the past. An individual does not necessarily have to be a programmer to use R. A beginner can use basic R functionalities to manipulate and extract data and create very simple and quick visualizations using the basic graphic tools. An intermediate R user can implement interactive visualizations, perform predictive modeling, or even create animated applications using packages developed by the R community. R will present you with the tools you need to process, manipulate, and communicate with your data, and it is not just limited to statistical analysis.

In this book, you will learn how to generate basic visualizations, understand the limitations and advantages of using certain visualizations, develop interactive visualizations and applications, understand various data exploratory functions in R, and finally learn ways of presenting the data to our audience. This book is aimed at beginners and intermediate users of R who would like to go a step further in using their complex data to convey a very convincing story to their audience.

What this book covers

Chapter 1, A Simple Guide to R, is a quick tutorial on getting started with R. You will learn how to install packages, access help on R, construct and edit matrices, create and manipulate data frames, and write and save plots.

Chapter 2, Basic and Interactive Plots, introduces some of the basic R plots, such as scatter, line, and bar charts. We will also discuss the basic elements of interactive plots using the googleVis package in R. This chapter is a great resource for understanding the basic R plotting techniques.

Chapter 3, Heat Maps and Dendrograms, starts with a simple introduction to dendrograms and further introduces the concept of clustering techniques. The second half of this chapter discusses heat maps and integrating heat maps with dendrograms to get a more complete picture.

Chapter 4, Maps, discusses the importance of spatial data and various techniques used to visualize geographic data in R. You will learn how to generate static as well as interactive maps in R. The chapter discusses the topic of shape files and how to use them to generate a cartogram.

Chapter 5, The Pie Chart and Its Alternatives, is a detailed discussion on how to generate pie charts in R. You will also learn about the various criticisms of pie charts and how the pie chart is transformed to overcome them. The chapter also provides you with various alternatives used by data scientists and visualization artists to overcome the limitation of a pie chart.

Chapter 6, Adding the Third Dimension, dives into constructing 3D plots. This chapter also introduces packages such as rgl and animation, which are used to create interactive 3D plots.

Chapter 7, Data in Higher Dimensions, demonstrates the use of visualizations that are used to display data in higher dimension. You will learn the techniques to generate sunflower plots, hexbin plots, Chernoff faces, and so on. This chapter also discusses the usefulness of network, radial, and coxcomb plots, which have been widely used in news.

Chapter 8, Visualizing Continuous Data, illustrates the use of visualizations to display time series data. The chapter also discusses some general concepts related to visualizing correlations, the shape of the distribution, and detection of outliers using box and whisker plots.

Chapter 9, Visualizing Text and XKCD-style Plots, illustrates the use of text in creating effective visualizations. This chapter focuses mainly on techniques to create word clouds, phase tree, and comparison clouds in R. You will also learn how to use the XKCD package to introduce humor in visualizations.

Chapter 10, Creating Applications in R, shows you the techniques to create presentations and R markdown documents for publishing on a blog or a website. The chapter further discusses the XML package used to extract and visualize data as well as using shiny package used to create interactive applications.

What you need for this book

You need to download R to generate the visualizations. You can download and install R using the CRAN website available at http://cran.r-project.org/. All the recipes were written using RStudio. RStudio is an integrated development environment (IDE) for R and can be downloaded from http://www.rstudio.com/products/rstudio/. Many of the visualizations are created using R packages and they are discussed in their respective recipes.

In few of the recipes, I have introduced users to some other open source platforms such as ScapeToad, ArcGIS, and Mapbox. Their installation procedures are outlined in their respective recipes.

Who this book is for

Having studied economics, I am not a software programmer myself and have written this book for readers new to R and visualization. This book does not delvento complex R code or complex data manipulating techniques, and it is written keeping in mind new and intermediate R users interested in learning about data visualization and data exploration techniques.

The book aims at teaching you the implementation of interactive and animated data visualizations and not just the basic R techniques. However, I have introduced some basic functionalities in Chapter 1, A Simple Guide to R and Chapter 2, Basic and Interactive Plots.

Wherever possible, I have provided references to websites, blogs, and journals, which can be explored to learn more about specific functions, graphics, animations, or even basic functionalities in R.

Sections

In this book, you will find several headings that appear frequently (Getting ready, How to do it, How it works, There's more, and See also).

To give clear instructions on how to complete a recipe, we use these sections:

Getting ready

This section tells you what to expect in the recipe, and describes how to set up any software or any preliminary settings required for the recipe.

How to do it…

This section contains the steps required to follow the recipe.

How it works…

This section usually consists of a detailed explanation of what happened in the previous section.

There's more…

This section consists of additional information about the recipe in order to make the reader more knowledgeable about the recipe.

See also

This section provides helpful links to other useful information for the recipe.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to <[email protected]>, and mention the book title via the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the erratasubmissionform link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.

Piracy

Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at <[email protected]> with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.

Questions

You can contact us at <[email protected]> if you are having a problem with any aspect of the book, and we will do our best to address it.

Chapter 1. A Simple Guide to R

In this chapter, we will cover the following recipes:

Installing packages and getting help in RData types in RSpecial values in RMatrices in REditing a matrix in RData frames in REditing a data frame in RImporting data in RExporting data in RWriting a function in RWriting if else statements in RBasic loops in RNested loops in RThe apply, lapply, sapply, and tapply functionsUsing par to beautify a plot in RSaving plots

Installing packages and getting help in R

If you are a new user and have never launched R, you must definitely start the learning process by understanding the use of install.packages(), library(), and getting help in R. R comes loaded with some basic packages, but the R community is rapidly growing and active R users are constantly developing new packages for R.

As you read through this cookbook, you will observe that we have used a lot of packages to create different visualizations. So the question now is, how do we know what packages are available in R? In order to keep myself up-to-date with all the changes that are happening in the R community, I diligently follow these blogs:

RbloggerRstudio blog

There are many blogs, websites, and posts that I will refer to as we go through the book. We can view a list of all the packages available in R by going to http://cran.r-project.org/, and also http://www.inside-r.org/packages provides a list as well as a short description of all the packages.

Getting ready

We can start by powering up our R studio, which is an Integrated Development Environment (IDE) for R. If you have not downloaded Rstudio, then I would highly recommend going to http://www.rstudio.com/ and downloading it.

How to do it…

To install a package in R, we will use the install.packages() function. Once we install a package, we will have to load the package in our active R session; if not, we will get an error. The library() function allows us to load the package in R.

How it works…

The install.packages() function comes with some additional arguments but, for the purpose of this book, we will only use the first argument, that is, the name of the package. We can also load multiple packages by using install.packages(c("plotrix", "RColorBrewer")). The name of the package is the only argument we will use in the library() function. Note that you can only load one package at a time with the library() function unlike the install.packages() function.

There's more…

It is hard to remember all the functions and their arguments in R, unless we use them all the time, and we are bound to get errors and warning messages. The best way to learn R is to use the active R community and the help manual available in R.

To understand any function in R or to learn about the various arguments, we can type ?<name of the function>. For example, I can learn about all the arguments related to the plot() function by simply typing ?plot or ?plot() in the R console window. You will now view the help page on the right side of the screen. We can also learn more about the behavior of the function using some of the examples at the bottom of the help page.

If we are still unable to understand the function or its use and implementation, we could go to Google and type the question or use the Stack Overflow website. I am always able to resolve my errors by searching on the Internet. Remember, every problem has a solution, and the possibilities with R are endless.

See also

Flowing Data (http://flowingdata.com/): This is a good resource to learn visualization tools and R. The tutorials are based on an annual subscription.Stack Overflow (http://stackoverflow.com/): This is a great place to get help regarding R functions.Inside-R (http://www.inside-r.org/): This lists all the packages along with a small description.Rblogger (http://www.r-bloggers.com/): This is a great webpage to learn about new R packages, books, tutorials, data scientists, and other data-related jobs.R forge (https://r-forge.r-project.org/).R journal (http://journal.r-project.org/archive/2014-1/).