Just as the doppler shift of an incoming train whistle makes the pitch sound higher, and when the train is moving away from you the pitch sounds deeper, the velocity of a galaxy moving towards us or away from us will shift the frequency and wavelength of the features in its galaxy spectrum. If a galaxy is moving at a positive velocity (away from us), the observed wavelength of any particular feature will be larger than its restframe wavelength. If a galaxy is moving with a negative velocity (towards us), the feature will have a smaller wavelength than in the restframe.
Let us begin by examining the restframe spectrum of a galaxy, so named because the source of the light is at rest relative to us. The key features in this spectrum appear at the wavelengths they would occupy if we studied the elements that produce them in a laboratory here on Earth.
You should be able to identify the same pattern of emission lines within both spectra, with one critical difference – all of the lines in the lower spectrum appear at longer wavelengths than their restframe counterparts. We have the same set of four hydrogen features at blue wavelengths, but now all four lines lie to the right at wavelengths larger than 4000 Angstroms. We next encounter three emission lines which cluster together; rather than exhibiting light blue and green colours, they have shifted towards longer wavelengths and yellower colours. Finally, the features found in the red portion of the spectrum are at redder and redder colours. Because all of the features have shifted together to the right, in the direction of the red end of the optical spectrum, we say that this spectrum is redshifted. The faster than the galaxy is moving away from us, the larger the shift in wavelength of every feature within the spectrum.
Once you are comfortable with the concept of a redshifted spectrum, your sense of balance may lead you to ask about the existence of its natural counterpart, the blueshifted spectrum. Though most galaxies withint the Universe are expanding away from us, and have redshifted spectra, we have a few neighbors which are coming closer and closer to the Milky Way and have blueshifted spectra.
Here is a sample blueshifted spectrum. You can see, for example, how the three features near to 5000 Angstroms now lie well below this limit, and have turned from green to blue. The bluest features in our spectrum are now in danger of falling off of the left hand edge of the spectrum; if the galaxy were moving slightly faster towards us, they would have been shifted to shorter wavelength ultraviolet wavelengths, and be lost from our optical spectrum. You would be able to identify the overall shift of the spectral lines even without them, however, by keying on the three lines near to 5000 Angstroms and their characteristic relative positions.
At first it may seem incorrect that such galaxies would exist – after all, if the entire Universe is expanding outwards, how could anything be getting closer to us? The solution to this puzzle becomes clear when we consider the effect of gravity. Because gravity is a strong force which attracts nearby objects together, when galaxies are quite close to each other their self-attraction can overwhelm the overall expansion of space.