Not long after the last quotation from a Shakespeare sonnet, The Next Generation returned with another. This time, the opening lines of Sonnet 29 give the characters the opportunity to contemplate the piece of work that is a man. The question in this episode is whether Data, an android, is the property of Star Fleet or whether he has autonomy. The character who reads the sonnet wants to take him apart to learn more about him; not unreasonably, Data has objected and announced his resignation from Star Fleet. But, once again, that's the surface level of the use of the sonnet here. Data, in attempting to become human, allows the other characters (and, of course, the audience) to think about what it means to be human. The rest of the sonnet (see below) is one way to answer that question.
XXIX.
When, in disgrace with fortune and men's eyes,
I all alone beweep my outcast state
And trouble deaf heaven with my bootless cries
And look upon myself and curse my fate,
Wishing me like to one more rich in hope,
Featured like him, like him with friends possess'd,
Desiring this man's art and that man's scope,
With what I most enjoy contented least;
Yet in these thoughts myself almost despising,
Haply I think on thee, and then my state,
Like to the lark at break of day arising
From sullen earth, sings hymns at heaven's gate;
For thy sweet love remember'd such wealth brings
That then I scorn to change my state with kings.
For more connections between Star Trek and Shakespeare, head to Shakespeare and Star Trek Complete.