DEV Community


Posted on • Updated on

Ploting graph with R-programming

πŸ”₯ Introduction to R (1)

πŸ”₯ Data Structure (2)

πŸ”₯ Statistical value (mean, median, mode etc) (3)

πŸ”₯ Tabular Presentation of Data (4)

πŸ”₯ Ploting graph with R

πŸ”₯ constructing frequency distribution with R (6)

The following is an introduction for plotting simple graphs with the R Programming Language. Each example builds on the previous one.
In statistic while trying to do analysis on data the most important way of displaying information is the use of graphs. so let's see different kind of graph we can plot with codes.

Types of Graph

  1. Line Charts
  2. Bar Charts
  3. [Histograms]
  4. Pie Charts
  5. Dotcharts
  6. Misc

Line Charts

First we'll produce a very simple graph using the values in the weight vector:


copy the following codes

# Define the cars vector with 8 values
weight <- c(1, 6, 11, 14, 19, 22, 26, 33)
# Graph the weight vector with all defaults
Enter fullscreen mode Exit fullscreen mode


Alt Text
that is just a simple way to draw a line graph. all your value will be dotted. but that is not nice enough we need to add some attribute that made up perfect graph.

Title and Colors

Let's add a title, a line to connect the points, and some color with the following codes
Example 1.2

weight <- c(1, 6, 11, 14, 19, 22, 26, 33)
# Graph weight using red points overlay  by a line and use o as the dot
plot(weight, type="o", col="red",font.main=11)
# Create a title with a green, bold font
title(main="Autos", col.main="red", font.main=4)
Enter fullscreen mode Exit fullscreen mode

Alt Text


the plot() function is used to plot the graph. it can take some parameters like vector ,type and color.
Vectors: is the data will want to use to plot the graph.
type: is the kind of mark and line we want to use to specify dot on the graph. it is dot by default and can be change to whatever we want e.g "h","p","s",'S','l' and 'c'
color: this is use to give our own preference color.

can we plot two line graph in one graph?? Yeah! we can and we shall take a look at that later. read the next article.

πŸ”₯ Ploting graph with R

πŸ”₯ Bar Charts


πŸ”₯Pie Charts


Top comments (1)

arvindpdmn profile image
Arvind Padmanabhan

R in fact has three plotting systems: base, lattice, ggplot2. See for more info. I often use ggplot2.