You are on page 1of 9

Read CSV, Excel Files in R

• Data could exist in various formats. For each


format R has a specific function and argument.
This tutorial explains how to import data to R.
Read CSV

• One of the most widely data store is the .csv


(comma-separated values) file formats. R
loads an array of libraries during the start-up,
including the utils package. This package is
convenient to open csv files combined with
the reading.csv() function. Here is the syntax
for read.csv
Reading Excel files in R
• To read an Excel file into R first install the
package or tick the box in the Packages list to
load it or load the library.
• install.packages("xlsx")
• Load the library
• library(xlsx)## Loading required package:
rJava## Loading required package: xlsxjars
Reading Excel files in R
• The read.xlsx function provides a high level
API for reading data from an Excel worksheet.
It calls several low level functions in the
process. Its goal is to provide the conveniency
of read.table by borrowing from its signature.
R - Bar Charts

• A bar chart represents data in rectangular bars


with length of the bar proportional to the
value of the variable. R uses the
function barplot() to create bar charts. R can
draw both vertical and Horizontal bars in the
bar chart. In bar chart each of the bars can be
given different colors.
R - Bar Charts

• Syntax
• The basic syntax to create a bar-chart in R is −
• barplot(H,xlab,ylab,main, names.arg,col)
• Following is the description of the parameters used −
• H is a vector or matrix containing numeric values used in bar
chart.
• xlab is the label for x axis.
• ylab is the label for y axis.
• main is the title of the bar chart.
• names.arg is a vector of names appearing under each bar.
• col is used to give colors to the bars in the graph.
Ggplot2 in R
• ggplot2 is a R package dedicated to data
visualization. It can greatly improve the quality
and aesthetics of your graphics, and will make
you much more efficient in creating them.
• ggplot2 allows to build almost any type of
chart. The R graphallery focuses on it so
almost every section there starts with
Ggplot2 in R

• Elements of ggplot2
• Let’s start by installing the ggplot2 package by
calling install.packages(“ggplot2”)
• install.packages("ggplot2")Now we need to
load the package by using
the library() function.
• library(ggplot2)

You might also like