I agree with nytoparis about 5 days/4 night in Vieques. But just if you are a true beach lover. Otherwise you could get bored by day 4. This should be done on your first portion when you arrive to Puerto Rico.
About staying 2 days in El Yunque area will depend on your preferences. I would just drive to El Yunque on my way back from Vieques, or go there as a day trip when staying in San Juan. If your focus is just to visit El Yunque, then you would not need to stay nearby because it is just a 35-45 min drive from San Juan. This way you minimize changing hotels and all the packing unpacking.
Now if you can not get a return flight out of Aguadilla, to simplify driving and hotel changing, after your return from Vieques drive west towards Rincon or Cabo Rojo for your second stay. For this area 3 days should be fine. You can visit Ponce, Rincon, Aguadilla, Arecibo in just day trips. As mentioned on another post, stop at the Arecibo caves on your drive to/from your next stay.
Then on the last portion stay in San Juan for about 3-4 days. I would cut back one day from Vieques. Old San Juan can take One full day, El Yunque another full day, third day for Condado/beach/OSJ time, and the fourth day is departure time.