I would like a table where cells are colored (defined by values)

47 Views Asked by At

Suppose that I have a dataset with firms and the associated addresses. In my analysis I am putting them into different groups. So, my dataframe, which I call ResultPlot, could look like this:

Name Address Group

Firm1, Berlin, group1

Firm2, Copenhagen, NA

Firm3, Amsterdam, group2

Firm4, Stockholm, group1

Firm5, Frankfurt, group2 ...

In this example, Firm1 and Firm4 are put in the same group, and Firm3 and Firm5 are put in another group. In general a group may consist of any number of firms, and a firm may also be independent (no group). I can plot the group structure on a map by using the following code:

library(leaflet)
MyDomainColors=ResultPlot %>% select(Group) %>% distinct() %>% arrange()
MyDomainColors=as.vector(MyDomainColors[,1])

pal2 <- colorFactor(rainbow(length(MyDomainColors)), domain = MyDomainColors,na.color = "#808080")

leaflet(ResultPlot) %>% addProviderTiles(providers$CartoDB.PositronNoLabels) %>% addCircleMarkers(label=ResultPlot$Group, stroke = FALSE, fillOpacity = 1, radius=5, color = ~pal2(Group))

But I would also like a table (can be a picture) where firms are in the first column, while the next columns show the group structures. Here is an example that I made in Excel with one group structure (firm1 and firm4; firm3 and firm5):

enter image description here

I mean, the idea is that I change the column "Group" in the dataframe "ResultPlot", and the colors in the table should be adjusted automatically. I would like to have the same colors as in my leaflet plot (here I use "rainbow" which I found on the internet, but I am fine with setting colors in a different way). Also, I might look into different group structures, so it would be perfect if it was possible to add more columns with group structures ("Group structure 2", "Group structure 3", etc.).

0

There are 0 best solutions below