How to do it...

Perform the following steps to visualize a dataset:

  1. Load the iris data into the R session:
        > data(iris)  
  1. Calculate the frequency of species within the iris using the table command:
        > table.iris = table(iris$Species)
        > table.iris
        Output:
              setosa versicolor  virginica 
         50         50         50 
  1. As the frequency in the table shows, each species represents 1/3 of the iris data. We can draw a simple pie chart to represent the distribution of species within the iris:
        > pie(table.iris)
        Output:
The pie chart of species distribution
  1. The histogram creates a frequency plot of sorts along the x-axis. The following example produces a histogram ...

Get Machine Learning with R Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.