Nematicity has emerged as a key feature of cuprate superconductors, but its link to other fundamental properties such as superconductivity, charge order and the pseudogap remains unclear. Here we use measurements of transport anisotropy in YBa$_2$Cu$_3$O$_y$ to distinguish two types of nematicity. The first is associated with short-range charge-density-wave modulations in a doping region near $p = 0.12$. It is detected in the Nernst coefficient, but not in the resistivity. The second type prevails at lower doping, where there are spin modulations but no charge modulations. In this case, the onset of in-plane anisotropy - detected in both the Nernst coefficient and the resistivity - follows a line in the temperature-doping phase diagram that tracks the pseudogap energy. We discuss two possible scenarios for the latter nematicity.