Plotting a simple graph on R project

To plot a simple graph in R project, you have to work on “plot” function. Its usage is indicated by “plot(x, y, …)”, where x represents the x coordinates of points in the plot and y shows the y coordinates.

You can make a simple plot by writing the following code into the R-project.

x<-c(1,2,3)

y<-c(2,4,6)

plot(x,y)

You will get another window with R-Graphics as shown below;

Simple graph made on R-project

In “plot(x, y, …)”, “…” shows a variety of different arguments such as the graphical parameters. Arguments can be as follows;

  • type
  • main
  • sub
  • xlab
  • ylab
  • asp

Type shows the type of plot to be drawn. Most important types are the points represented by “p”, lines by “l”, both by “b”, “c” for the lines part alone of “b”, overplotted for “o”, histogram like vertical lines by “h”, stair steps by “s”, other steps by “S”, and no plotting by “n”.

You may try these types by writing the following into the R-Console.

x<-c(1,2,3)

y<-c(2,4,6)

plot(x,y,type=”S”)

You will get the following type of plot;

Simple graph with type S on R project

You may try with other types to remind these graphs and their types.

main gives title to the plot. You may get to know about this in R-project by writing as follows;

x<-c(1,2,3)

y<-c(2,4,6)

plot(x,y,type=”b”, main=”SayPeople.com”)

sub gives subtitle to the plot that will be shown below x-coordinate. You may check this by writing the following;

x<-c(1,2,3)

y<-c(2,4,6)

plot(x,y,type=”b”, main=”SayPeople.com”, sub=”science blog”)

xlab and ylab give label to x-axis and y-axis respectively. You may understand this by writing the following in the R-console.

x<-c(1,2,3)

y<-c(2,4,6)

plot(x,y,type=”b”, main=”SayPeople.com”, sub=”science blog”, xlab=”horizontal”, ylab=”vertical”)

asp shows y/x aspect ratio. You can check the aspect ratio by writing the following.

x<-c(1,2,3)

y<-c(2,4,6)

> plot(x,y,type=”b”, main=”SayPeople.com”, sub=”science blog”, xlab=”horizontal”, ylab=”vertical”, asp=2)

Source: R-project

saypeople

SayPeople.com gives you the news and information about Science, Research, Technology, Business and Islam.