简体   繁体   中英

Scatter plot with indication of the density of points

R's qplot function has a nifty alpha parameter for shading coincident points in a scatter plot darker. Here it is in action:

http://www.decisionsciencenews.com/2010/07/01/maps-without-map-packages

I'm wondering how to do the same in Mathematica. Here's code to grab the data from the above article and plot it, without the nifty shading:

data = Rest@Import[
  "http://www.decisionsciencenews.com/wp-content/uploads/2010/07/latlong.zip", 
  "latlong.csv"]

ListPlot[data, PlotRange -> {{-130, -65}, {23.5, 50.5}}, Frame -> True]

The question is, how to add the shading of the points?

I think this has a few different solutions. If you just want to adjust the opacity of every point you can:

ListPlot[data, PlotRange -> {{-130, -65}, {23.5, 50.5}}, 
 Frame -> True, PlotStyle -> Opacity[0.5]]

This produces a very similar effect as the plot in your link.

Custom color maps based on density are possible but my implementation does not produce pretty graphs yet.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM