Plotting of Data using Generic plots in R Programming – plot() Function

plot() function is defined as as generic function for plotting in R Language. It can be used to create basic graphs of different type .

Syntax:
plot(x, y, type)

Parameters:
x and y: coordinates of points to plot
type: the type of graph to create

Returns: different type of plots

Example 1:



filter_none

edit
close

play_arrow

link
brightness_4
code

# R program to plot a graph
  
# Values for x and y axis
x <- 1:5; y = x * x
  
# Using plot() function
plot(x, y, type = "l")
plot(x, y, type = "h")

chevron_right


Output:

In above example type=“l” stands for lines graph, type=“h” stands for ‘histogram’ like vertical lines.

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# R program to plot a graph
  
# Creating x and y-values
x - 1:5; y = x * x
  
# Using plot function
plot(x, y, type = "b")
plot(x, y, type = "s")
plot(x, y, type = "p")

chevron_right


Output:


Here, in above example type=“b” stands for both that means points are connected by a line

type=“s”indicates stair steps

type=“p” for points (by default).

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.