# Making section plots with oce and imagep()

section objects in the oce package are a convenient way of storing a series of CTD casts together – indeed, the object name derives from the common name for such a series of casts collected from a ship during a single campaign.

In it’s heart, a section object is really just a collection of ctd objects, with some other metadata. The CTD stations themselves are stored as a list of ctd objects in the @data slot, like:

List of 124
$:Formal class 'ctd' [package "oce"] with 3 slots$ :Formal class 'ctd' [package "oce"] with 3 slots
$:Formal class 'ctd' [package "oce"] with 3 slots$ :Formal class 'ctd' [package "oce"] with 3 slots
$:Formal class 'ctd' [package "oce"] with 3 slots$ :Formal class 'ctd' [package "oce"] with 3 slots
$:Formal class 'ctd' [package "oce"] with 3 slots$ :Formal class 'ctd' [package "oce"] with 3 slots
[list output truncated]


Just to prove it, we can plot make a standard ctd plot of one of them, by accessing them directly with the [[ accessor syntax. Let’s plot the 100th station:

## Making nice plots of the sections themselves

The main advantage of a section object is to be able to quickly make plots summarizing all the data in the section. This is accomplished using the plot method for section objects, which you can read about by doing ?"plot,section-method". For example, to make a contour plot of the temperature:

Ok, cool. But what about some colors? Use the ztype='image' argument!

## Finer control over the section plot

To get finer control over the section plot than is possible with the section plot() method, one trick I will sometimes do is extract the data I want from the section as a gridded matrix, and then plot the matrix directly using the imagep() function.

First, we “grid” the section so that all the stations comprise the same pressure levels:

Now, we can loop through the station fields, extracting the data as we go.

Basically, what we’re doing here is creating an empty matrix, then filling each row with the data from the section stations. We can make a quick plot with imagep():

Or we can do some fancier things, like use the colormap() function and plot some filled contours: