[英]R: color gps points that show up more times darker in color
I would like to plot gps points like a heat map - those that show up more times will be darker/warmer in color. 我想像热图一样绘制gps点-出现更多次的点将变暗/变暖。 My data look like this: 我的数据如下所示:
lon lat Freq
1 -121.93 68.28 1
2 -117.72 70.72 1
3 -110.69 68.75 1
4 -94.79 61.03 1
5 -93.80 58.63 1
6 -92.18 62.88 1
7 -89.68 46.15 3
8 -83.00 62.50 1
9 -78.99 56.41 1
10 -78.87 56.39 1
11 -71.30 65.95 1
12 -67.36 62.84 1
13 -67.35 62.86 1
14 -67.25 63.45 2
I can plot these data as follows: 我可以按以下方式绘制这些数据:
newmap<-getMap(resolution="low")
plot(newmap)
points(data3$V5, data3$V4, col = "red", pch = 15, cex = 0.5)
However, I would like the points that have a frequency of 2 or 3 (see Freq column) to be darker/warmer like a heat map, with an accompanying legend. 但是,我希望频率为2或3(参见“频率”列)的点像热图一样更暗/更暖,并带有图例。 It looks like there might be a solution using ggmap, but I have not been able to obtain a world map using ggmap. 似乎使用ggmap可能有解决方案,但我无法使用ggmap获得世界地图。 (I need a world map because I will be plotting far more gps points than in this example that cross the globe). (我需要一张世界地图,因为与这个例子相比,我要绘制的gps点要多得多)。 I like the way this outline of the world looks. 我喜欢这个世界轮廓的外观。
One option would be to set the opacity using rgb
instead of just putting in a color. 一种选择是使用rgb
设置不透明度,而不仅仅是设置颜色。 For instance 例如
points(data3$V5, data3$V4, col = rgb(1, 0, 0, 0.5), pch = 15, cex = 0.5)
With ggplot2: 使用ggplot2:
library(ggmap)
library(ggplot2)
world <- map_data("world")
ggplot() + geom_path(data=world, aes(x=long, y=lat, group=group)) +
geom_point(data=data3, aes(x=lon, y=lat, colour=Freq, size=sqrt(Freq/pi))) + scale_colour_gradientn(colours = rev(heat.colors(12))) +
scale_size(guide = FALSE)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.