It's perfectly fine to go aggro at times! In some matchups that's your best option overall. The best thing you can do for yourself as Mega Man is being what I'm going to call cautiously aggressive. Always try to be within the maximum range of your Jab/Nair/Ftilt Lemons, but only ever close in when you're confident you'll get something. In a lot of matchups and especially on stages with platforms Mega Man can capitalize in huge ways off of grabs or rogue aerial attacks.
Sometimes though it's best to hang back, in matchups like Samus, Ganondorf, and Ness it can be much more comfortable to simply sit at your lemon range and just keep firing away, fading in and out safely while tossing out metal blades and crash bombers to eat up more horizontal and vertical space. A lot of it comes with matchup experience and can even be on a player by player basis depending on how each opponent deals with pressure and projectiles.
For rushdown characters Mega Man has a few critical options to keep in mind:
1) Shield Grabbing is always a good option to keep in mind, throwing your opponent towards the nearest ledge both denies them space, and lets you either back off or put on pressure of your own. In a best case scenario it can lead to off stage play where Mega Man really shines and can gimp a huge swath of the roster.
2) Shielding or Spot Dodging into Mega Upper or Up Smash is an enormously good option in some matchups. Did a ROB player just throw their top at you or whiff a grab? Hit em with an up tilt. Did a Shiek just Dash Attack on your shield? Hit em with an up tilt. Not only does this retaliate in a big way (17%!), it also kills enemies absurdly early and puts them into the air.
3) Keep up a projectile wall. They can't hit you if they can't get close! This only works in matchups like Zero Suit Samus, Sonic, and Captain Falcon, where their options vs your projectiles are limited.
Try and keep each of these in mind and really experiment to find a way you enjoy playing vs each character. With Mega Man and in Smash 4 as a whole Matchup Experience is critical to doing well. Even if you're a better player if you have no experience fighting, let's say Peach for example, but that Peach has a lot of experience vs Mega Man, chances are you will lose. This game doesn't have that many terribly stilted matchups where you can just get by on knowledge of your own character. Keep your chin up and keep on playing.