Since you convert your x-axis data to the POSIXct
class, you can use the format
component of the scales
argument to specify the format of the axis labels:
xyplot(sales ~ week | carColor, data=salesData[order(salesData$week),],
type="l",
scales = list(
x = list(
format = "%d-%b" # Here's where you choose the format
)
),
xlab = "Date",
ylab = "Sales"
)
Lattice plots use the pretty
function to help determine which axis labels to draw. So
format(pretty(salesData$week), "%d-%b")
should in most cases return the labels that get drawn. Lattice (more specifically grid
) graphics also check for potential overlap of axis labels. In cases where the labels would potentially overlap, simply using pretty
may deviate from the labels that actually get drawn.