GRAPHS IN R PROGRAMMING
Tags: datascience, programming, r, tutorial
Published: 2021-11-25 12:03:08

#Creating Graphs
R is profoundly used for its substantial techniques for graphical interpretation of data of utmost importance of analysts. The primary styles are: dot plot, density plot (can be classified as histograms and kernel), line graphs, bar graphs (stacked, grouped and simple), pie charts (3D,simple and expounded), line graphs(3D,simple and expounded), box-plots(simple, notched and violin plots),    bar-plots and scatter-plots (simple with fit lines, scatter-plot matrices, high-density plots and 3-D plots).The foundational function for creating graphs: plot(). This includes how to build a graph, from adding lines and points to attaching a legend.
# The Workhorse of R Base Graphics The plot() Function
The plot() function forms the foundation for much of R’s base
graphing operations, serving as the vehicle for producing many
different kinds of graphs. plot() is a generic function, or a
placeholder for a family of functions. The function that is
actually called depends on the class of the object on which it is called. The basic syntax to create a line chart in R is −
## plot(v, type, col, xlab, ylab)
Following is the description of the parameters used −
->v :is a vector containing the numeric values.
->type :takes the value "p" to draw only the points, "l" to draw only the lines and "o" to draw
both points and lines.
->xlab :is the label for x axis.
->ylab :is the label for y axis.
->main :is the Title of the chart.
->col :is used to give colors to both the points and lines. 
#Some of the coloring functions in Graphs.
Function       Use
colors( )     Returns the built-in color names 
rgb( )        This function creates colors corresponding to the 
              given of the red, green and blue primaries. It 
              returns hex code of the color.
cm.colors( )  Create a vector of n contiguous colors.
rainbow( )    Create a vector of n contiguous colors.

and so on...

#TYPES OF GRAPHS:
-Bar plot  
    -Syntax:- barplot(H, xlab, ylab, main, names.arg, col)
         Following is the description of the parameters used − 
           -H is a vector or matrix containing numeric values 
            used in bar chart. 
           - xlab is the label for x axis. 
           -ylab is the label for y axis. 
           -main is the title of the bar chart. 
           -names.arg is a vector of names appearing under each 
            bar. 
           -col is used to give colors to the bars in the 
            graph. 
-Pie Chart 
     -Syntax:- pie(x, labels, radius, main, col, clockwise)
         Following is the description of the parameters used: 
             -x is a vector containing the numeric values used 
              in the pie chart. 
             - labels is used to give description to the 
               slices.
             -radius indicates the radius of the circle of the 
              pie chart.(value between −1 and +1).
             -main indicates the title of the chart.
             -col indicates the color palette.
             -clockwise is a logical value indicating if the 
              slices are drawn clockwise or anti clockwise.
-Histogram
     -Syntax:- hist(v,main,xlab,xlim,ylim,breaks,col,border)
          Following is the description of the parameters used − 
             -v is a vector containing numeric values used in 
              histogram.
             -main indicates title of the chart.  col is used 
              to set color of the bars.
             -border is used to set border color of each bar. 
             -xlab is used to give description of x-axis. 
             -xlim is used to specify the range of values on 
              the x-axis.
             -ylim is used to specify the range of values on 
              the y-axis.
             -breaks is used to mention breakpoints between 
              histogram cells 
             -counts: The count of values in a particular 
              range. 
             -mids: center point of multiple cells.
             -density: cell density