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).
Contact Us