Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.8k views
in Technique[技术] by (71.8m points)

Plotting basis (heat) maps in R

I'm trying to plot a basis map for the Midwest region in R but the closest solution I've found is a stat_density2d plot. Instead of plotting the frequencies I have a column of values called basis that are negative and positive and I'd like to reflect their distribution over a map as a heatmap. Is it possible? And are the non-ggmap solutions?

An example of what I want: enter image description here

The data:

    structure(list(crop_name = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L
), .Label = c("beans", "corn", "hrw", "milo"), class = "factor"), 
    year = c(2019, 2019, 2019, 2019, 2019, 2019, 2019, 2019, 
    2019, 2019, 2019, 2019, 2019, 2019, 2019, 2019, 2019, 2019, 
    2019, 2019, 2019, 2019, 2019, 2019, 2019, 2019, 2019, 2019, 
    2019, 2019, 2019, 2019, 2019, 2019, 2019, 2019, 2019, 2019, 
    2019, 2019, 2019, 2019, 2019, 2019, 2019, 2019, 2019, 2019, 
    2019, 2019, 2019, 2019, 2019, 2019, 2019, 2019, 2019, 2019, 
    2019, 2019, 2019, 2019, 2019, 2019, 2019, 2019, 2019, 2019, 
    2019, 2019, 2019, 2019, 2019, 2019, 2019, 2019, 2019, 2019, 
    2019, 2019, 2019, 2019, 2019, 2019, 2019, 2019, 2019, 2019, 
    2019, 2019, 2019, 2019, 2019, 2019, 2019, 2019, 2019, 2019, 
    2019, 2019, 2019, 2019, 2019, 2019, 2019, 2019, 2019, 2019, 
    2019, 2019, 2019, 2019, 2019, 2019, 2019, 2019, 2019, 2019, 
    2019, 2019, 2019, 2019, 2019, 2019, 2019, 2019, 2019, 2019, 
    2019, 2019, 2019, 2019, 2019, 2019, 2019, 2019, 2019, 2019, 
    2019, 2019, 2019, 2019, 2019, 2019, 2019, 2019, 2019, 2019, 
    2019, 2019), week = c(27, 27, 27, 27, 27, 27, 27, 27, 27, 
    27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 
    27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 
    27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 
    27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 
    27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 
    27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 
    27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 
    27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 
    27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 
    27, 27, 27, 27, 27, 27), basis = c(-0.320000052452087, -0.289999842643738, 
    -0.399999976158142, -0.289999842643738, -0.349999785423279, 
    -0.249999865889549, -0.220000132918358, -0.309999823570251, 
    -0.309999823570251, 0.199999943375587, 0.150000229477882, 
    0.150000229477882, -0.399999976158142, -0.309999823570251, 
    -0.0500000566244125, -0.349999785423279, 0.0200001150369644, 
    0.0200001150369644, 0.0200001150369644, -0.349999785423279, 
    -0.0700000375509262, -0.349999785423279, -0.349999785423279, 
    -0.399999976158142, -0.399999976158142, -0.249999865889549, 
    -0.0999997705221176, -0.340000033378601, -0.249999865889549, 
    -0.249999865889549, -0.0999997705221176, -0.550000071525574, 
    -0.349999785423279, -0.109999999403954, -0.309999823570251, 
    -0.520000100135803, -0.449999928474426, -0.449999928474426, 
    -0.200000151991844, -0.360000014305115, -0.28000009059906, 
    -0.309999823570251, -0.0500000566244125, -0.0999997705221176, 
    -0.419999957084656, -0.419999957084656, -0.320000052452087, 
    -0.370000004768372, -0.309999823570251, -0.360000014305115, 
    -0.200000151991844, -0.109999999403954, -0.109999999403954, 
    -0.399999976158142, -0.0500000566244125, 1.33514404865309e-07, 
    -0.109999999403954, -0.320000052452087, -0.269999861717224, 
    0.0200001150369644, -0.320000052452087, -0.349999785423279, 
    -0.349999785423279, -0.349999785423279, -0.419999957084656, 
    -0.309999823570251, -0.370000004768372, -0.370000004768372, 
    -0.200000151991844, -0.0199998468160629, -0.0199998468160629, 
    -0.449999928474426, -0.149999961256981, -0.449999928474426, 
    0.0200001150369644, -0.249999865889549, -0.300000071525574, 
    -0.300000071525574, -0.249999865889549, -0.0799997895956039, 
    -0.0500000566244125, -0.349999785423279, -0.249999865889549, 
    0.199999943375587, -0.289999842643738, -0.0500000566244125, 
    -0.200000151991844, -0.200000151991844, -0.149999961256981, 
    -0.149999961256981, -0.249999865889549, -0.109999999403954, 
    -0.249999865889549, -0.0500000566244125, -0.0500000566244125, 
    0.0200001150369644, -0.449999928474426, 0.0099998852238059, 
    0.0499998480081558, -0.300000071525574, -0.389999985694885, 
    -0.300000071525574, -0.200000151991844, -0.140000209212303, 
    -0.449999928474426, -0.479999899864197, -0.479999899864197, 
    -0.0199998468160629, -0.0999997705221176, -0.0700000375509262, 
    1.33514404865309e-07, -0.0999997705221176, -0.0999997705221176, 
    -0.269999861717224, -0.269999861717224, -0.269999861717224, 
    0.199999943375587, -0.0500000566244125, -0.240000113844872, 
    -0.389999985694885, -0.309999823570251, 0.0499998480081558, 
    -0.399999976158142, -0.349999785423279, -0.449999928474426, 
    -0.449999928474426, -0.449999928474426, -0.449999928474426, 
    -0.28000009059906, -0.449999928474426, -0.349999785423279, 
    -0.249999865889549, -0.249999865889549, -0.149999961256981, 
    -0.449999928474426, -0.109999999403954, -0.349999785423279, 
    -0.309999823570251, -0.0500000566244125, -0.0799997895956039, 
    -0.249999865889549, -0.28000009059906, -0.249999865889549, 
    -0.399999976158142, -0.200000151991844, -0.200000151991844, 
    -0.109999999403954, -0.169999942183495, -0.490000128746033, 
    -0.0500000566244125), loc_id = structure(c(1L, 467L, 506L, 
    453L, 349L, 564L, 4L, 582L, 116L, 438L, 139L, 135L, 636L, 
    407L, 627L, 493L, 142L, 142L, 388L, 508L, 7L, 615L, 615L, 
    616L, 616L, 567L, 628L, 469L, 144L, 144L, 417L, 147L, 148L, 
    149L, 588L, 150L, 509L, 152L, 85L, 9L, 420L, 408L, 154L, 
    155L, 156L, 156L, 454L, 455L, 10L, 11L, 470L, 338L, 338L, 
    637L, 629L, 12L, 546L, 456L, 14L, 595L, 457L, 385L, 385L, 
    385L, 159L, 424L, 494L, 495L, 565L, 163L, 163L, 362L, 554L, 
    165L, 16L, 568L, 590L, 591L, 394L, 511L, 630L, 617L, 18L, 
    323L, 614L, 171L, 172L, 172L, 596L, 120L, 377L, 547L, 578L, 
    175L, 175L, 87L, 513L, 440L, 20L, 569L, 375L, 21L, 514L, 
    473L, 618L, 179L, 179L, 597L, 181L, 182L, 121L, 185L, 107L, 
    378L, 378L, 378L, 361L, 516L, 351L, 458L, 409L, 25L, 517L, 
    122L, 489L, 188L, 465L, 108L, 27L, 189L, 496L, 192L, 555L, 
    194L, 363L, 342L, 497L, 459L, 197L, 29L, 390L, 30L, 556L, 
    32L, 428L, 598L, 343L, 199L, 200L, 201L), .Label = c("1569", 
    "1570", "1571", "1573", "1579", "1581", "1582", "1583", "1593", 
    "1595", "1598", "1601", "1602", "1603", "1608", "1611", "1617", 
    "1618", "1619", "1626", "1627", "1630", "1633", "1638", "1639", 
    "1640", "1644", "1651", "1652", "1653", "1654", "1655", "1658", 
    "1660", "1661", "1664", "1665", "1667", "1676", "1677", "1678", 
    "1679", "1681", "1683", "1687", "1689", "1693", "1695", "1697", 
    "1698", "1699", "1702", "1703", "1710", "1713", "1714", "1718", 
    "1721", "1725", "1727", "1728", "1729", "1732", "1733", "1740", 
    "1741", "1746", "1747", "1748", "1749", "1753", "1763", "1764", 
    "1771", "1773", "1774", "1776", "1778", "1785", "1786", "1788", 
    "1927", "1933", "1962", "1963", "1968", "1971", "1980", "1985", 
    "1989", "1990", "1993", "1998", "1999", "2000", "2014", "2018", 
    "2031", "2035", "2922", "2924", "2925", "2926", "2927", "2928", 
    "2929", "2930", "2931", "2932", "2933", "2935", "2936", "2938", 
    "2939", "2941", "2980", "2981", "2983", "2984", "2985", "2986", 
    "2987", "2992", "2993", "2994", "2996", "2997", "2998", "2999", 
    "3109", "3282", "4231", "4232", "4233", "4234", "4235", "4236", 
    "4237", "4238", "4239", "4240", "4241", "4242", "4244", "4245", 
    "4246", "4247", "4248", "4249", "4250", "4251", "4252", "4253", 
    "4254", "4255", "4256", "4257", "4258", "4260", "4261", "4262", 
    "4263", "4264", "4266", "4267", "4268", "4269", "4270", "4271", 
    "4272", "4273", "4274", "4275", "4277", "4278", "4279", "4280", 
    "4281", "4282", "4283", "4284", "4285", "4286", "4287", "4288", 
    "4289", "4290", "4291", "4294", "4295", "4296", "4297", "4298", 
    "4299", "4300", "4301", "4302", "4303", "4304", "4305", "4306", 
    "4307", "4308", "4309", "4310", "4311", "4312", "4313", "4314", 
    "4315", "4316", "4317", "4318", "4319", "4320", "4321", "4322", 
    "4323", "4324", "4325", "4326", "4327", "4328", "4329", "4330", 
    "4331", "4333", "4335", "4336", "4337", "4338", "4339", "4341", 
    "4342", "4343", "4344", "4345", "4346", "4347", "4348", "4349", 
    "4351", "4352", "4353", "4354", "4355&

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...