Search code examples
rdplyrgroup-bymappinggeography

Group by in R to represent counts per county on a map?


picture of data

I have the data above in which I need to represent the companies in the last column for every US county on a map. The dea is to be able to hover over a county and have it say the company names. It came from an Excel pivot table which I collapsed down to a csv. My strategy is to add a column that summarizes the company counts per county so I can map that one variable. I'm not sure the best way to do that, I'm assuming a column value that reads "Alabama Power Company (4) Wetterhorn Wireless L.L.C. (3)" or "Alabama Power Company Alabama Power Company Alabama Power Company Alabama Power Company Wetterhorn Wireless L.L.C. Wetterhorn Wireless L.L.C. Wetterhorn Wireless L.L.C." or something like that. Would I use a group by to do that? What's the best way to summarize this pivot table on a map?


Solution

  • I finally figured out how to represent it using aggregate:

    summary = aggregate(dt$company, list(dt$ccounty), paste, collapse=" ")

    this yields all the names of the winners