[英]World map plot with latitude and longitude points
I am trying to plot a world map of specific lake sites (lat and long) and the further differentiate the points according to the two variables (Model for color and Size for Total), aiming at the end to have a sort of bubble plot over a world map. 我正在尝试绘制特定湖点(纬度和经度)的世界地图,并根据两个变量(颜色的模型和总计的大小)进一步区分这些点,以期最终在上方绘制一种气泡图世界地图。
That's how my data (WD) looks like (data.frame) 这就是我的数据(WD)的样子(data.frame)
WD <- read.csv(file.choose(), header = TRUE)
head(WD)
Country Lake Lat Long Model Total
1 USA Annie, lake 27.994549 -81.604644 PB 0
2 USA Annie, lake 27.994549 -81.604644 DD 1
3 Australia Baroon, reservoir -26.706919 152.870361 PB 0
4 Australia Baroon, reservoir -26.706919 152.870361 DD 2
5 England Bassenthwaite, lake 54.6525 -3.225833 PB 3
6 England Bassenthwaite, lake 54.6525 -3.225833 DD 0
I've downloaded the world map using 我已经使用下载了世界地图
library("ggmap")
library(maptools)
library(maps)
mapWorld <- borders("world", colour="gray50", fill="white")
plotting the map without points is ok 绘制没有点的地图是可以的
mp <- ggplot() + mapWorld
then I try to add the points by 然后我尝试通过添加点
mp <- mp+ geom_point(data=WD, aes(x=Long, y=Lat) ,color=WD$Model,alpha=0.5, size=WD$Total)
but when I try to plot mp the below error appears and I don't know how to figure this out 但是当我尝试绘制mp时出现以下错误,我不知道如何解决
Error: Discrete value supplied to continuous scale
Without having your data there were a few things that stuck out to me. 在没有您的数据的情况下,有些事情仍然困扰着我。 In your geom_point layer I think your size and color should be inside the aes() like so: 在您的geom_point图层中,我认为您的大小和颜色应在aes()内,如下所示:
mp + geom_point(data = WD, aes(x = Long, y = Lat, color = Model, size = Total), alpha = 0.5)
Those may not be the only problems, and it is usually a good idea to start with the basics of a ggplot layer and see if that will work, and then get fancy with the color and size. 这些可能不是唯一的问题,通常从ggplot层的基础知识开始,看一看是否可行,然后看一下颜色和大小,通常是个好主意。 That can help nail down where the problem is. 这可以帮助确定问题所在。 So in your case, just try and see if it will plot with the Lat and Long first. 因此,在您的情况下,请尝试先将其与纬度和经度一起绘制。
I would also suggest checking that you don't have any NA's in your data and that the dataframe vectors are the appropriate class for each spot you are trying to plug it in at (factor, character, numeric, etc...). 我还建议您检查数据中是否没有NA,并且数据帧向量是否适合您要插入的每个位置(因子,字符,数字等)。 Each of those problems have wasted me a great deal of time at one point or another... 这些问题中的每一个都浪费了我大量的时间。
Good luck! 祝好运!
thanks for the tips. 感谢您的提示。 I found out there one of the variables was a factor, but even after correcting this the problem persisted. 我发现其中一个变量是一个因素,但是即使更正了该问题,问题仍然存在。 So I restarted R several times and it magically worked 所以我重新启动了R好几次了
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.