Major chords and pentatonic scales
In many songs the melody and lead solos follow the form of using the major chord's pentatonic scale. In other words, if the song is using a C major chord, you'll probably be hitting the right notes if you're playing a c major pentatonic scale. (I'll address blues and minor chords elsewhere.)
The sections below are based on the CAGED System of learning chords. Google it if you don't know what it is, there are easily hundreds of sites that explain it. In brief, it points out that you can barre any of the open chords to make another chord elsewhere on the neck.
Each sections shows the standard open form of a major chord along with the form of the pentatonic to play with it. The nut is to the left or top for each pattern, but these can be played anywhere on the neck. The larger, fading circles are the chord notes and the smaller circles are the pentatonic notes. As you can see, the chord tones are all in the associated pentatonic scale.
The same chords and patterns are shown in both a vertical and a horizontal display because some people have trouble with one form or the other.
A standard C major chord, and the C major pentatonic.
A standard A major chord, and the A major pentatonic.
A standard G major chord, and the G major pentatonic.
A standard E major chord, and the E major pentatonic. If you have trouble seeing the chord, think of it as an F, which is essentially a barred E.
A standard D major chord, and the D major pentatonic.
Using the patterns
All of the chords in the CAGED system can be barred, at least to some degree. So somewhere on the neck there is a place to play each of the 5 forms as various inversions of the chord. In other words, there are at least 5 ways to play an E chord.
Use these patterns to play a lead pattern wherever you happen to be on the neck. For instance, if you're playing an E chord as a barred A (starting on the 7th fret), then play the A form lead over it.