In the exercises below, we will see features of the famous lattice graphics package.

Please see the documentation before trying the exercises.

Answers to the exercises are available here.

If you obtained a different (correct) answer than those listed on the solutions page, please feel free to post your answer as a comment on that page.

**Exercise 1**

Lattice’s structure is similar to base r’s formula interface. Load the library and air quality data and create the histogram of Solar.R. The right hand side of the formula represents the x-axis in a 2D viz. Give the plot a descriptive name and label the x-axis as “Solar Level.”

**Exercise 2**

Create the same plot using the number of bins as 20.

Hint: nint param

**Exercise 3**

In the same plot, use the type count AND type percent to see how the plot looks when using different types.

**Exercise 4**

Create a density plot with the air quality data for the Solar.R variable. Density plot is another alternative to histograms.

**Exercise 5**

Create a scatter plot of the Ozone vs. Solar.R via lattice.

**Exercise 6**

In the same plot, add a reference line representing the distribution using “abline.”

**Exercise 7**

Suppose you want to see the different distribution of a continuous variable with respect to a categorical variable; for example, in the Iris data, to see the distribution of Sepal.Width with respect to different species. Create a box and whisker plot.

**Exercise 8**

Make the bw plot to see the whisker extend to the extreme outliers.

**Exercise 9**

It’s easy to see how 3 species varies when comparing Sepal.Length with respect to Sepal.Width. How can you plot them in one plot?

**Exercise 10**

Similarly see the similar Solar.R for every month as a density plot in a single plot.

**What's next:**

- Explore all our (>1000) R exercises
- Find an R course using our R Course Finder directory
- Subscribe to receive weekly updates and bonus sets by email
- Share with your friends and colleagues using the buttons below

Yudha says

This is fun, thanks