【发布时间】:2021-11-02 02:46:38
【问题描述】:
我正在尝试在 R 中创建我的数据地图。创建地图时,没有显示轮廓,也没有显示点的填充。弗吉尼亚的地图是使用 Rs map_data 函数制作的。当地图拉起时,它只是黑色的,没有县线。我尝试将多边形“颜色”更改为“col”和“fill”。不用找了。此外,地图上的数据点也是黑色的——没有颜色,尽管我有我的代码。我的代码有错误吗?
这是我的数据集示例
| urban_continuum | p.shannon | p.simpson | latitude | longitude |
|---|---|---|---|---|
| A_Rural | 4.609 | 0.9334 | 37.7659 | -75.7578 |
| C_Suburb | 6.420 | 0.9973 | 38.0241 | -78.5535 |
| D_City | 5.961 | 0.9959 | 38.8183 | -77.0820 |
| B_Town | 5.033 | 0.9923 | 37.7879 | -80.0086 |
这是我的代码:
Virginia=map_data("state", region = "virginia")
VA.pdiv=ggplot()+
geom_polygon(data=Virginia, aes(x=long, y=lat, group=group,
color="white"))+
geom_point(data = VA.county1, aes(x=longitude, y=latitude,
fill=p.shannon,
size=p.simpson,
shape=urban_continuum))+
scale_fill_gradient(low = "blue", high = "orange")+
labs(x="Longitude", y="Latitude",
fill="Shannon Diversity Index of VA Plants",
size="Simpson Diversity Index of VA Plants",
title = "Plant Diversity in Virginia")+
coord_map()
VA.pdiv
当我尝试其他人的建议时,我得到了颜色点,但仍然没有县线。我将删除 p.simpson 或 p.shannon 以帮助澄清,但现在我只是解决县线问题。 这是我的代码:
require(ggplot2)
library(ggplot2)
#pull up our base map
Virginia= map_data("county", region="Virginia")
ggplot()+
geom_polygon(data = Virginia,
aes(x = long,
y = lat,
group = group)) +
geom_point(data = VA.county1,
aes(x = longitude,
y = latitude,
color = p.shannon,
size=p.simpson,
shape = urban_continuum)) +
scale_color_gradient(low = "blue", high = "orange") +
labs(x = "Longitude",
y = "Latitude",
color = "Shannon Diversity Index of VA Plants",
size = "Simpson Diversity Index of VA Plants",
shape= "Urban Continuum",
title = "Plant Diversity in Virginia") +
coord_map()
【问题讨论】:
-
您能否为
VA.county1添加一些数据以使代码可重现?谢谢 -
请澄清您的具体问题或提供其他详细信息以准确突出您的需求。正如目前所写的那样,很难准确地说出你在问什么。
-
我很抱歉。我添加了一些示例数据,以及一些澄清细节。