First, I'd like to applaud your curiosity in the matter. Second, when it comes to any sort of scientific discussion, there is absolutely nothing which can truly be considered random (and by extension coincidental).
Consider this graph of planetary velocity provided by: http://www.bbc.co.uk/education/guides/zk8hvcw/revision/4
Notice any similarities between this and your line of best fit for averaged density as a function of distance?
The first part of my answer refers to the formation of our own little piece of the universe; when our solar system was formed, it is theorized that virtually all matter ended up taking on the form of a massive spinning disk. The distribution of matter as well as gravitational forces within the forming system and the rest of the universe would all have contributed to how these stellar bodies formed.
Why doesn't earth's atmosphere, composed of gaseous nitrogen, oxygen, carbon dioxide, and other gasses simply dissipate into the vastness of space? Yes, partially this is due to the electromagnetic field blocking radiation from the sun from torching our little blue paradise, but forget that for a moment. It's gravity isn't it? At the same time, the atmosphere isn't being pressed against the surface of the earth into an insanely thin layer (relatively speaking it is quite thin). This is due to pressure; the gasses repel each other and seek to dissipate. However, the further away those gasses get, the weaker the gravitational force gets.
At a mere 14,000 km from the center of earth, acceleration due to gravity is a mere 2 meters per second squared. Little more than a fifth what it is at the surface. However, even from this distance from our star (nearly 150,000,000 km), the sun's gravitational pull is only reduced to .06% of the strength of earth's gravity. Simply put, in order for matter to remain confined to earth, acceleration due to the gravitational pull of earth must exceed the acceleration of the matter due to any other forces, such as pressure forcing gas outwards.
How would this be effected if earth were closer to the sun? Well, not only would surface temperatures increase, but the relative strength of the sun's gravitational pull would also increase. Higher temperatures mean greater pressure, and greater pressure within an atmosphere would force gas away from the surface, where planetary gravity continues to lessen; at a point, the sun's gravity itself would be enough to siphon gas away from the planet. Going further away from the sun, thermal energy decreases, and the gravitational pull of the sun also lessens.
In order for matter to exist in close proximity to the sun without simply being pulled into the sun, a combination of factors including momentum, relative gravitational field strength (compared with the sun), boiling point, and propensity to absorb or reflect solar radiation must be present. To boil it down, how dense is the matter, how does the matter react to applied energy, how is the density altered by this reaction, and what are the relative gravitational strengths of the body of matter (i.e. planet) and star? A gas giant with a composition such as that of Jupiter, in Mercury's orbit, for example, should not be capable of maintaining its gaseous atmosphere in the presence of the Sun's gravity and thermal energy.
Now, the gravitational pull of the sun on atmospheres has less of an effect at the present point in time, but when the solar system was in its infancy, matter lacking adequate density to be bound within a stellar body's gravitational pull (or the absence of a massive body to provide such gravitational strength) would have been pulled into that of the soon-to-be star.
There are a myriad of other factors, though I hope this helps to explain some of your confusion regarding the correlation between orbital distance and average density. The simplest way to try to wrap your head about such concepts is to consider all possible relationships. If you have distance on the independent access, what would happen if you tried plotting something like gravitational pull or solar radiation intensity per square meter on the dependent? Perhaps you could even create plots for atmospheric and planetary composition.