Move categorical legend plotting code to private method