Replace alternative names with indices and add a legend