Visualising the dozens of overlapping sets formed by categories of cloud services
Author
Carl Goodwin
Published
November 14, 2017
Modified
January 20, 2023
When visualising a small number of overlapping sets, Venn diagrams work well. But what if there are more. Here’s a tidyverse approach to the exploration of sets and their intersections.
In Let’s Jitter I looked at a relatively simple set of cloud-service-related sales data. G-Cloud data offers a much richer source with many thousands of services documented by several thousand suppliers and hosted across myriad web pages. These services straddle many categories. I’ll use these data to explore the sets and where they cross.
I’m going to focus on the Cloud Hosting lot. Suppliers document the services they want to offer to Public Sector buyers. Each supplier is free to assign each of their services to one or more service categories. It would be interesting to see how these categories overlap when looking at the aggregated data.
I’ll begin by harvesting the URL for each category’s search results. And I’ll also capture the number of search pages for each category. This will enable me to later control how R iterates through the web pages to extract the required data.
So now I’m all set to parallel process through the data at two levels. At category level. And within each category, I’ll iterate through the multiple pages of search results, harvesting 100 service IDs per page.
I’ll also auto-abbreviate the category names so I’ll have the option of more concise names for less-cluttered plotting later on.
Tip
Hover over the numbered code annotation symbols for REGEX explanations.
I like Venn diagrams. But to create one I’ll first need to do a little prep as ggVennDiagram (Gao 2022) requires separate character vectors for each set.
Venn diagrams work best with a small number of sets. So we’ll select four categories.
four_cats <- all_cats[c("CAAH", "PAAS", "OBS", "IND")]four_cats |>ggVennDiagram(label ="count", label_alpha =0) +scale_fill_gradient(low = cols[5], high = cols[3]) +scale_colour_manual(values = cols[c(rep(4, 4))]) +labs(x ="Category Combinations", y =NULL, fill ="# Services",title ="The Most Frequent Category Combinations",subtitle =glue("Focusing on Four {version} Service Categories"),caption ="Source: digitalmarketplace.service.gov.uk\n" )
Let’s suppose I want to find out which Service IDs lie in a particular intersection. Perhaps I want to go back to the web site with those IDs to search for, and read up on, those particular services. I could use purrr’s reduce to achieve this. For example, let’s extract the IDs at the heart of the Venn which intersect all categories.
Sometimes though we need something a little more scalable than a Venn diagram. The ggupset package provides a good solution. Before we try more than four sets though, I’ll first use the same four categories so we may compare the visualisation to the Venn.
set_df <- data_df |>filter(abbr %in%c("CAAH", "PAAS", "OBS", "IND")) |>mutate(category =list(cat), .by = service_id) |>distinct(service_id, category) |>mutate(n =n(), .by = category)set_df |>ggplot(aes(category)) +geom_bar(fill = cols[1]) +geom_label(aes(y = n, label = n), vjust =-0.1, size =3, fill = cols[5]) +scale_x_upset() +scale_y_continuous(expand =expansion(mult =c(0, 0.15))) +theme(panel.border =element_blank()) +labs(x ="Category Combinations", y =NULL,title ="The Most Frequent Category Combinations",subtitle =glue("Focusing on Four {version} Service Categories"),caption ="Source: digitalmarketplace.service.gov.uk" )
Now let’s take a look at the intersections across all the categories. And let’s suppose that our particular interest is all services which appear in one, and only one, category.
set_df <- data_df |>filter(n() ==1, lot =="Cloud Hosting", .by = service_id) |>mutate(category =list(cat), .by = service_id) |>distinct(service_id, category) |>mutate(n =n(), .by = category)set_df |>ggplot(aes(category)) +geom_bar(fill = cols[2]) +geom_label(aes(y = n, label = n), vjust =-0.1, size =3, fill = cols[3]) +scale_x_upset(n_sets =10) +scale_y_continuous(expand =expansion(mult =c(0, 0.15))) +theme(panel.border =element_blank()) +labs(x ="Category Combinations", y =NULL,title ="10 Most Frequent Single-Category Services",subtitle ="Focused on Service Categories in the Cloud Hosting Lot",caption ="Source: digitalmarketplace.service.gov.uk" )
Suppose we want to extract the intersection data for the top intersections across all sets. I could use functions from the tidyr package to achieve this.
Archiving Backup And Disaster Recovery | Compute And Application Hosting | Nosql Database | Other Database Services | Networking | Platform As A Service | Search | Block Storage | Object Storage | Other Storage Services
76
Logging And Analysis
67
Other Database Services
57
Infrastructure And Platform Security
57
Compute And Application Hosting | Platform As A Service
51
Archiving Backup And Disaster Recovery | Compute And Application Hosting | Content Delivery Network | Data Warehousing | Distributed Denial Of Service Attack Protection | Firewall | Infrastructure And Platform Security | Intrusion Detection | Platform As A Service | Protective Monitoring
39
Relational Database
38
Container Service
34
Message Queuing And Processing
29
Infrastructure And Platform Security | Intrusion Detection | Logging And Analysis | Protective Monitoring
27
Archiving Backup And Disaster Recovery | Compute And Application Hosting | Nosql Database | Relational Database | Other Database Services | Networking | Platform As A Service | Search | Block Storage | Other Storage Services
23
Archiving Backup And Disaster Recovery | Compute And Application Hosting | Firewall | Infrastructure And Platform Security | Intrusion Detection | Load Balancing | Logging And Analysis | Networking | Platform As A Service | Protective Monitoring
22
Block Storage | Object Storage | Other Storage Services
22
Compute And Application Hosting | Container Service | Platform As A Service
21
Archiving Backup And Disaster Recovery | Other Storage Services
20
Infrastructure And Platform Security | Networking
20
And I can compare this table to the equivalent ggupset (Ahlmann-Eltze 2020)visualisation.
set_df <- data_df |>filter(lot =="Cloud Hosting") |>mutate(category =list(cat), .by = service_id) |>distinct(service_id, category) |>mutate(n =n(), .by = category)set_df |>ggplot(aes(category)) +geom_bar(fill = cols[5]) +geom_label(aes(y = n, label = n), vjust =-0.1, size =3, fill = cols[4]) +scale_x_upset(n_sets =22, n_intersections =21) +scale_y_continuous(expand =expansion(mult =c(0, 0.15))) +theme(panel.border =element_blank()) +labs(x ="Category Combinations", y =NULL,title ="Top Intersections Across all Sets",subtitle ="Focused on Service Categories in the Cloud Hosting Lot",caption ="Source: digitalmarketplace.service.gov.uk" )
And if I want to extract all the service IDs for the top 5 intersections, I could use dplyr (Wickham et al. 2022) and tidyr (Wickham and Girlich 2022) verbs to achieve this too.
Summarising below the packages and functions used in this post enables me to separately create a toolbox visualisation summarising the usage of packages and functions across all posts.