R language Access Menu

Data visualization with graphs

R has great plotting capabilities and this forms an important part of data analysis. Two methods are most commonly used: plot function of base R and ggplot and other functions of ggplot2 package.

Plot function is good for simple graphs but beyond that complex syntax is needed.

code:
        > xx = c(1,3,6,8,19)
        > yy = c(13, 46, 53, 78, 110)
        > plot(xx, yy)

To plot age versus lwt of bwdf dataset:

code: 
       > with(bwdf, plot(age, lwt))

Note that 'with' function creates a micro-environment where the variable are looked for in the bwdf dataset. Otherwise, one can also get same result with following command:

code:
       > plot(bwdf$age, bwdf$lwt)
output (graph):

            Graph

 

There are many other plot commands in base R also such as barplot and boxplot.

                                                                         


    Comments & Feedback