Legal compliance affects data collection by imposing restrictions on how data can be gathered, used, and shared. Researchers must obtain informed consent from participants, anonymize data where possible, and ensure data security measures are in place. Non-compliance can lead to fines, legal action, and loss of public trust.