Click the desktop, select View > Group Stacks By, then pick an option. Or Control-click the desktop, select Group Stacks By, then choose an option.