Charts and Graphs

In a real-world scenario enormous amount of data is produced on daily basis, so, interpreting it can be somewhat hectic. Here data visualization comes into play because it is always better to visualize that data through charts and graphs, to gain meaningful insights instead of screening huge Excel sheets. Let’s see some basic plots in R Programming.

Bar Chart:

R uses the function barplot() to create bar charts. Here, both vertical and Horizontal bars can be drawn.

Example:

R




# Create the data for the chart
A <- c(17, 32, 8, 53, 1)
 
# Plot the bar chart
barplot(A, xlab = "X-axis", ylab = "Y-axis",
        main ="Bar-Chart")


Output:

Note: For more information, refer Bar Charts in R

Histograms:

R creates histogram using hist() function.

Example: 

R




# Create data for the graph.
v <- c(19, 23, 11, 5, 16, 21, 32,
       14, 19, 27, 39)
 
# Create the histogram.
hist(v, xlab = "No.of Articles ",
     col = "green", border = "black")


 
 Output:

 

Note: For more information, refer Histograms in R language

Scatter plots:

The simple scatterplot is created using the plot() function.

Example:

R




# Create the data for the chart
A <- c(17, 32, 8, 53, 1)
B <- c(12, 43, 17, 43, 10)
 
 
# Plot the bar chart
plot(x=A, y=B, xlab = "X-axis", ylab = "Y-axis",
        main ="Scatter Plot")


Output:

 

Note: For more information, refer Scatter plots in R Language

Line Chart:

The plot() function in R is used to create the line graph.

Example:

R




# Create the data for the chart.
v <- c(17, 25, 38, 13, 41)
 
# Plot the bar chart.
plot(v, type = "l", xlab = "X-axis", ylab = "Y-axis",
        main ="Line-Chart")


 
 Output:

 

Note: For more information, refer Line Graphs in R Language.

Pie Charts:

R uses the function pie() to create pie charts. It takes positive numbers as a vector input.

Example:

R




# Create data for the graph.
geeks<- c(23, 56, 20, 63)
labels <- c("Mumbai", "Pune", "Chennai", "Bangalore")
 
# Plot the chart.
pie(geeks, labels)


 
 Output:

 

Note: For more information, refer Pie Charts in R Language

Boxplots:

Boxplots are created in R by using the boxplot() function.

R




input <- mtcars[, c('mpg', 'cyl')]
 
# Plot the chart.
boxplot(mpg ~ cyl, data = mtcars,
        xlab = "Number of Cylinders",
        ylab = "Miles Per Gallon",
        main = "Mileage Data")


 
 Output:

 

Note: For more information, refer Boxplots in R Language

For more articles refer Data Visualization using R

Learn R Programming

R is a Programming Language that is mostly used for machine learning, data analysis, and statistical computing. It is an interpreted language and is platform independent that means it can be used on platforms like Windows, Linux, and macOS.

In this R Language tutorial, we will Learn R Programming Language from scratch to advance and this tutorial is suitable for both beginners and experienced developers).

Similar Reads

Why Learn R Programming Language?

R programming is used as a leading tool for machine learning, statistics, and data analysis. R is an open-source language that means it is free of cost and anyone from any organization can install it without purchasing a license. It is available across widely used platforms like windows, Linux, and macOS. R programming language is not only a statistic package but also allows us to integrate with other languages (C, C++). Thus, you can easily interact with many data sources and statistical packages. Its user base is growing day by day and has vast community support. R Programming Language is currently one of the most requested programming languages in the Data Science job market that makes it the hottest trend nowadays....

Key Features and Applications

Some key features of R that make the R one of the most demanding job in data science market are:...

Download and Installation

There are many IDE’s available for using R in this article we will dealing with the installation of RStudio in R....

Hello World in R

R Program can be run in several ways. You can choose any of the following options to continue with this tutorial....

Fundamentals of R

...

Data Types

Variables:...

Basics of Input/Output

...

Decision Making

...

Control Flow

...

Loop Control Statements

...

Functions

...

Data Structures

...

Error Handling

Each variable in R has an associated data type. Each data type requires different amounts of memory and has some specific operations which can be performed over it. R supports 5 type of data types. These are –...

Charts and Graphs

...

Statistics

Taking Input from the User:...

Contact Us