【发布时间】:2019-07-10 14:39:57
【问题描述】:
我正在绘制显示不同国家盈亏的世界地图。 我已经绘制了地图,我准备并加入了数据,我在最后一步。
我的数据集是“data_profit”,“Total_profit”是我使用的值(负值和正值)——它用于根据值用颜色填充地图。 剩下的代码是地图绘制。
ditch_the_axes <- theme(
axis.text = element_blank(),
axis.line = element_blank(),
axis.ticks = element_blank(),
panel.border = element_blank(),
panel.grid = element_blank(),
axis.title = element_blank()
)
terra<-ggplot(data_profit, aes( x = long, y = lat, group = group )) +
geom_polygon(aes(x = long, y = lat,fill = Total_profit),color = "black")+
coord_fixed(1.3) +
theme_bw() +
ditch_the_axes+
scale_fill_gradient2( low="black", high="red", space ="Lab" )
data_profit <-
structure(list(long = c(-69.8991241455078, -69.8957061767578,
-69.9421920776367, -70.004150390625, -70.0661163330078, -70.0508804321289
), lat = c(12.4520015716553, 12.4229984283447, 12.4385251998901,
12.50048828125, 12.5469722747803, 12.5970697402954), group = c(1,
1, 1, 1, 1, 1), order = 1:6, region = c("Aruba", "Aruba", "Aruba",
"Aruba", "Aruba", "Aruba"), Total_profit = c(0, 0, 0, 0, 0, 0
)), row.names = c(NA, 6L), class = "data.frame")
所以,问题是最终的地图没有显示负值(应该是黑色和灰色的阴影)。我检查了“Total_profit”值是否为数字(使用 is.finite 和 is.numeric)。 您知道要在代码中更改什么吗?
【问题讨论】:
-
Marta New,欢迎来到 SO!您收到了反对票,因为您的问题既不可重现(我们没有您的数据样本),我们也看不到问题(没有图像!)。请使这个问题可重现,包括样本数据(最好是我们可以用
dput(head(x))轻松复制的数据),以及显示问题的图表使用你的样本数据给我们。这意味着您需要找到足够具体的数据样本来显示问题,但又不能大到导致网页臃肿。推荐阅读:stackoverflow.com/questions/5963269 -
感谢 Marta New 添加数据 - 但是,这不会重现示例!在发布问题和代码之前,我始终建议在空会话中运行它 - 在给定的示例数据上运行代码时,您将看到结果
标签: r ggplot2 statistics