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.

        > 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:

       > 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:

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



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


    Comments & Feedback