The mad Ophelia associates rosemary with remembrance and rue with grace:
175 There's rosemary, that's for remembrance;
176 pray you, love, remember.
There's rue for you, and
182 here's some for me; we may call it herb of grace
183 a' Sundays.
Perdita condenses this bundle of associations into a coherent explanation when she welcomes Polixenes and Camillo to the sheep-shearing feast:
Reverend sirs,
74 For you there's rosemary and rue; these keep
75 Seeming and savor all the winter long.
76 Grace and remembrance be to you both,
77 And welcome to our shearing! (Win.4.4.73-77)
The associations are probably convention: the gardener in Richard II calls rue the "sour herb of grace" (Ri2 3.4.105).
'Rosemary' occurs outside this bundle of associations in Romeo and Juliet (3), King Lear, and Pericles
17 September 1999