This is determined by the facet, which returns a data frame, than when joined to the data to be plotted tells us which panel it should appear in, where that panel appears in the grid, and what scales it uses.
g_train_layout(panel, facet, data, plot_data)
an updated panel object
the panel object to train
the facetting specification
a list of data frames (one for each layer), and one for the plot
the default data frame
As well as the layout info, this function also adds empty lists in which to house the x and y scales.