简体   繁体   English

R散点图按密度着色

[英]R scatterplot colored by density

I am creating a plot of GPS traces. 我正在创建GPS轨迹图。 That is, I want a plot that has a map as base layer (working with ggmap) and ontop of the map I plot all the points (lat/lon) (works also with geom_point). 也就是说,我想要一个以地图为基础层的图(使用ggmap),并在地图的顶部绘制所有点(纬度/经度)(也适用于geom_point)。 Now what is left, is the color of all those point that I want to represent the density of the points. 现在剩下的就是我要表示这些点的密度的所有这些点的颜色。 I experimented with density2d stat, which gives me a color with color=..level.. but then also modifies the position of my point and does not show all points. 我尝试了density2d stat,它为我提供了color = .. level ..的颜色,但同时也修改了我的点的位置,并且不显示所有点。 I do want to plot all the points with a color derived from the density. 我确实想用从密度导出的颜色来绘制所有点。 How would I do this? 我该怎么做?

ok the hint to alpha values did what I want, if I add my points twice, first in black and then another time in red with some small alpha 好的,alpha值的提示就达到了我想要的效果,如果我将点加两次,首先是黑色,然后是红色,带有一些小的alpha

brauns <- get_map(location,zoom = 11, source = "cloudmade", maptype = 118540, api_key = apikey)
bmap <- ggmap(brauns,darken= c(0.1,"white"))
bmap <- bmap + geom_point(data = knime.in, aes(x = MAPPED_LON, y = MAPPED_LAT), size = 1)
bmap <- bmap + geom_point(data = knime.in, aes(x = MAPPED_LON, y = MAPPED_LAT),col="red",alpha=0.07, size = 1)

Now, can you think of a way to add a legend to it? 现在,您能想到一种添加图例的方法吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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