Relation between average density of planets and their distance from the sun 
In this graph,I plotted the points as (Distance from the Sun,Average Density) of the planets.Distance of planets from the sun are in Astronomical units and the average density is $gram/cm^3$
I also plotted the graph of $6/x$ and log $x$.
To my astonishment,
The points associated with Earth,Mars,Jupiter,Uranus lies almost perfectly on graph of 6/x.
And the points associated with Uranus,Saturn and Neptune almost lies on the graph of log x.In both cases x is the the distance of the sun from planet in astronomical units.
Is this just a coincidence or there is any scientific reason for this coincidence?
 A: Your experiment with real data is fantastic!  I applaud your curiosity, and investigation into the planets.  Unfortunately, I don't think there's anything to your results (sorry!).
Astrophysics
The conventional wisdom used to be that planetary density would decrease with increasing distance away from a parent star, because that's what the disks around young stars look like [1] before they form planets.  This idea completely fails in light of exoplanetary data which now includes thousands of planets in many hundreds of star systems.  The end result is that planet formation is extremely complicated, and different types of planets tend to form in different places.  In addition to that, there are numerous reasons to believe that planets move around a good amount after they've formed.  So, observationally, there is no consistent relation between density and distance.
Statistics
If you try to plot enough relations, things will fit (e.g. Kepler's Shapes, and the Titus-Bode Law).  The robustness of trends and correlations drop rapidly when, 1) data is arbitrary excluded (e.g. Mercury and Venus), 2) arbitrary split up your data, and 3) use arbitrary measures of goodness of fit (e.g. how close points look to a line on a certain plot).  In fact, for robust statistical measurements, one needs to consider how many models were attempted to be fit, before considering how robust results seem.
[1] Even this is only approximately true... there were some more complicated reasons based on lifetimes of different substances in the disks, but that's not too important here.
A: Taking in account that the solar energy received on planet decreases as $1/r^2$, there you have a direct relation. Far planets are much colder and able to condensate gases that otherwise will be lost, closer ones are rocks with very little atmosphere. But going further from Jupiter(which is almost hydrogen) this does not matter anymore and they will more or less have a constant composition.
But a lot of other factors have to be taken in account(original structure of the cloud in which planets where formed, atmosphere, solar pressure, etc) so I believe that statistic about this are quite inconclusive with so little data to consider.
A: 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.
