**R language** is mostly used for the statistics and data analytics purpose to represent the data graphically in the software. To represent those data graphically, charts and graphs are used in R.

There are hundreds of charts and graphs present in R. For example, bar plot, box plot, mosaic plot, dot chart, coplot, histogram, pie chart, scatter graph, etc.

Below are the basic charts and graphs in R:

#### Bar Plot or Bar Chart

Bar plot or Bar Chart in R is used to represent the values in data vector as height of the bars. The data vector passed to the function is represented over y-axis of the graph. Bar chart can behave like histogram by using **table()** function instead of data vector.

**Syntax: **

barplot(data, xlab, ylab)

**where, **

datais the data vector to be represented on y-axis

xlabis the label given to x-axis

ylabis the label given to y-axis

**Note:** To know about more optional parameters in ** barplot()** function, use below command in R console:

help("barplot")

**Example:**

`# defining vector ` `x <` `-` `c(` `7` `, ` `15` `, ` `23` `, ` `12` `, ` `44` `, ` `56` `, ` `32` `) ` ` ` `# output to be present as PNG file ` `png(` `file` `=` `"barplot.png"` `) ` ` ` `# plotting vector ` `barplot(x, xlab ` `=` `"GeeksforGeeks Audience"` `, ` ` ` `ylab ` `=` `"Count"` `, col ` `=` `"white"` `, ` ` ` `col.axis ` `=` `"darkgreen"` `, ` ` ` `col.lab ` `=` `"darkgreen"` `) ` ` ` `# saving the file ` `dev.off() ` |

*chevron_right*

*filter_none*

**Output:**

#### Pie Diagram or Pie Chart

Pie chart is circular chart divided into different segments according to the ratio of data provided. The total value of pie is 100 and the segments tells the fraction of the whole pie. It is another method to represent statistical data in graphical form and

function is used to perform the same.**pie()**

**Syntax:**

pie(x, labels, col, main, radius)

**where, **

xis data vector

labelsshows names given to slices

colfills the color in the slices as given parameter

mainshows title name of the pie chart

radiusindicates radius of the pie chart. It can be between -1 to +1

**Note:** To know about more optional parameters in

function, use below command in R console:**pie()**

help("pie")

**Example:**

Assume, vector x indicates the number of articles present on GeeksforGeeks portal in categories names(x)

`# defining vector x with number of articles ` `x <` `-` `c(` `210` `, ` `450` `, ` `250` `, ` `100` `, ` `50` `, ` `90` `) ` ` ` `# defining labels for each value in x ` `names(x) <` `-` `c(` `"Algo"` `, ` `"DS"` `, ` `"Java"` `, ` `"C"` `, ` `"C++"` `, ` `"Python"` `) ` ` ` `# output to be present as PNG file ` `png(` `file` `=` `"piechart.png"` `) ` ` ` `# creating pie chart ` `pie(x, labels ` `=` `names(x), col ` `=` `"white"` `, ` `main ` `=` `"Articles on GeeksforGeeks"` `, radius ` `=` `-` `1` `, ` `col.main ` `=` `"darkgreen"` `) ` ` ` `# saving the file ` `dev.off() ` |

*chevron_right*

*filter_none*

**Output:**

Pie chart in 3D can also be created in R by using following syntax but requires** plotrix** library.

**Syntax:**

pie3D(x, labels, radius, main)

**Note:** To know about more optional parameters in `pie3D()`

function, use below command in R console:

help("pie3D")

**Example: **

`# importing library plotrix for pie3D() ` `library(plotrix) ` `# defining vector x with number of articles ` `x <` `-` `c(` `210` `, ` `450` `, ` `250` `, ` `100` `, ` `50` `, ` `90` `) ` ` ` `# defining labels for each value in x ` `names(x) <` `-` `c(` `"Algo"` `, ` `"DS"` `, ` `"Java"` `, ` `"C"` `, ` `"C++"` `, ` `"Python"` `) ` ` ` `# output to be present as PNG file ` `png(` `file` `=` `"piechart3d.png"` `) ` ` ` `# creating pie chart ` `pie3D(x, labels ` `=` `names(x), col ` `=` `"white"` `, ` `main ` `=` `"Articles on GeeksforGeeks"` `, ` `labelcol ` `=` `"darkgreen"` `, col.main ` `=` `"darkgreen"` `) ` ` ` `# saving the file ` `dev.off() ` |

*chevron_right*

*filter_none*

**Output:**

#### Histogram

Histogram is a graphical representation used to create a graph with bars representing the frequency of grouped data in vector. Histogram is same as bar chart but only difference between them is histogram represents frequency of grouped data rather than data itself.

**Syntax:**

hist(x, col, border, main, xlab, ylab)

**where, **

xis data vector

colspecifies the color of the bars to be filled

borderspecifies the color of border of bars

mainspecifies the title name of histogram

xlabspecifies the x-axis label

ylabspecifies the y-axis label

**Note:** To know about more optional parameters in

function, use below command in R console:**hist()**

help("hist")

**Example: **

`# defining vector ` `x <` `-` `c(` `21` `, ` `23` `, ` `56` `, ` `90` `, ` `20` `, ` `7` `, ` `94` `, ` `12` `, ` ` ` `57` `, ` `76` `, ` `69` `, ` `45` `, ` `34` `, ` `32` `, ` `49` `, ` `55` `, ` `57` `) ` ` ` `# output to be present as PNG file ` `png(` `file` `=` `"hist.png"` `) ` ` ` `# hist(x, main = "Histogram of Vector x", ` ` ` `xlab ` `=` `"Values"` `, ` ` ` `col.lab ` `=` `"darkgreen"` `, ` ` ` `col.main ` `=` `"darkgreen"` `) ` ` ` `# saving the file ` `dev.off() ` |

*chevron_right*

*filter_none*

**Output:**

#### Scatter Plot

Scatter plot is another type of graphical representation used to plot the points to show relationship between two data vectors. One of the data vector is represented on x-axis and another on y-axis.

**Syntax:**

plot(x, y, type, xlab, ylab, main)

**Where, **

xis the data vector represented on x-axis

yis the data vector represented on y-axis

typespecifies the type of plot to be drawn. For example, “l” for lines, “p” for points, “s” for stair steps, etc.

xlabspecifies the label for x-axis

ylabspecifies the label for y-axis

mainspecifies the title name of the graph

**Note:** To know about more optional parameters in

function, use below command in R console:**plot()**

help("plot")

**Example:**

`# taking input from dataset Orange already present in R ` `orange <` `-` `Orange[, c(` `'age'` `, ` `'circumference'` `)] ` ` ` `# output to be present as PNG file ` `png(` `file` `=` `"plot.png"` `) ` ` ` `# plotting ` `plot(x ` `=` `orange$age, y ` `=` `orange$circumference, xlab ` `=` `"Age"` `, ` `ylab ` `=` `"Circumference"` `, main ` `=` `"Age VS Circumference"` `, ` `col.lab ` `=` `"darkgreen"` `, col.main ` `=` `"darkgreen"` `, ` `col.axis ` `=` `"darkgreen"` `) ` ` ` `# saving the file ` `dev.off() ` |

*chevron_right*

*filter_none*

**Output:**

If a scatter plot has to be drawn to show relation between 2 or more vectors or to plot the scatter plot matrix between the vectors, then

function is used to satisfy the criteria.**pairs()**

**Syntax for basic use of **

**pairs()**function

pairs(~formula, data)

**where, **

~formulais the mathematical formula such as ~a+b+c

datais the dataset form where data is taken in formula

**Note:** To know about more optional parameters in pairs() function, use below command in R console:

help("pairs")

**Example :**

`# output to be present as PNG file ` `png(` `file` `=` `"plotmatrix.png"` `) ` ` ` `# plotting scatterplot matrix ` `# using dataset Orange ` `pairs(~age ` `+` `circumference, data ` `=` `Orange, ` `col.axis ` `=` `"darkgreen"` `) ` ` ` `# saving the file ` `dev.off() ` |

*chevron_right*

*filter_none*

**Output:**

#### Box Plot

Box plot shows how the data is distributed in the data vector. It represents five values in the graph i.e., minimum, first quartile, second quartile(median), third quartile, the maximum value of the data vector.

**Syntax:**

boxplot(x, xlab, ylab, notch)

**where, **

xspecifies the data vector

xlabspecifies the label for x-axis

ylabspecifies the label for y-axis

notch,if TRUE then creates notch on both the sides of the box

**Note:** To know about more optional parameters in

function, use below command in R console:**boxplot()**

help("boxplot")

**Example:**

`# defining vector with ages of employees ` `x <` `-` `c(` `42` `, ` `21` `, ` `22` `, ` `24` `, ` `25` `, ` `30` `, ` `29` `, ` `22` `, ` ` ` `23` `, ` `23` `, ` `24` `, ` `28` `, ` `32` `, ` `45` `, ` `39` `, ` `40` `) ` ` ` `# output to be present as PNG file ` `png(` `file` `=` `"boxplot.png"` `) ` ` ` `# plotting ` `boxplot(x, xlab ` `=` `"Box Plot"` `, ylab ` `=` `"Age"` `, ` `col.axis ` `=` `"darkgreen"` `, col.lab ` `=` `"darkgreen"` `) ` ` ` `# saving the file ` `dev.off() ` |

*chevron_right*

*filter_none*

**Output:**

## Recommended Posts:

- R - Bar Charts
- R - Pie Charts
- Adding Colors to Charts in R Programming
- Create Dot Charts in R Programming - dotchart () Function
- R - Line Graphs
- Plotting Graphs using Two Dimensional List in R Programming
- Introduction to Graphs
- Class 8 NCERT Solutions - Chapter 15 Introduction to Graphs - Exercise 15.3
- Compute Variance and Standard Deviation of a value in R Programming - var() and sd() Function
- Finding Day and Month on a Specific Date in R Language - weekday() and month() function
- Difference between node.js require and ES6 import and export
- Code Optimization Technique (logical AND and logical OR)
- How to select and upload multiple files with HTML and PHP, using HTTP POST?
- Contains and Between-And operators in SAS Programming
- What are the differences and Similarities Between Lumen and Laravel?
- Generate an array of given size with equal count and sum of odd and even numbers
- Find Location and Character Vector of an Object with partial name in R Language - apropos() and find() Function
- Binding rows and columns of a Data Frame in R - bind_rows() and bind_cols() Function
- Calculate the Floor and Ceiling values in R Programming - floor() and ceiling() Function
- Naming Rows and Columns of a Matrix in R Programming - rownames() and colnames() Function

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.