Nested Donut Chart

I have a data frame showing the number of patents by category by country.

I want to create a nested doughnut plot showing the proportion of patents per category on the inner plot and then the breakdown of patent classes by country on the outer plot. Alternatively, I want to show the proportion of countries patenting on the inner plot and then the breakdown of patent classes on the outer plot.

I tried webr and it does this but I have little control over formatting. I prefer to do this in ggplot but I am getting my knickers in a serious knot.

I am trying to implement this solution How to create a ggplot2 pie and donut chart on same plot? but I am getting confused by how to split patent class labels.

I have 3073 patents, grouped into 8 patent classes for 119 countries.

My data can be accessed here: data/patents.Rdata at master · aterhorst/data · GitHub

class_breakdown <- lens_data %>%
  select(class = value, country_code = `Country Code`, country = `Country Name`) %>%
  mutate(country_code = ifelse(is.na(country), "XX", country_code),
         country = ifelse(country_code == "XX", "Unknown", country)) %>%
  group_by(class, country) %>%
  summarise(patents = sum(n())) 

Can someone help me here, please?

The data aren't suitable for this presentation because the number of patents is too heavily concentrated in one country

I agree that a pie or donut chart is not appropriate here. Your patent counts are spread across several orders of magnitude, which requires a logarithmic scale. Also, you have too many countries to mark with colour in one plot.

Look at this possible solution. I put a limit on the total number of patents in a country, below this limits all countries are aggregated to "Others". And I use a logarithmic scale. This code will need a lot of tweaking to make a clean, readable plot.

limit <- 30
pat_country <- patents |> 
  group_by(country) |>
  summarise(total = sum(patents)) |> 
  mutate(country_n = if_else(total > limit, country, "Others"))

patents |> 
  left_join(pat_country, by = "country") |> 
  group_by(class, country_n) |> 
  summarise(patents = sum(patents)) |> 
  ggplot(aes(x = class, y = patents, colour = country_n)) +
  geom_point(size = 2) +
  scale_colour_brewer(type = "qual") +
  theme_bw() +
  theme(
    axis.text.x = element_text(angle = 45, hjust = 1),
    panel.grid = element_blank()
  ) +
  scale_y_log10() +
  annotation_logticks(sides = "l")

1 Like

Thanks. This is a useful solution. I appreciate your efforts!

Yes, China is patenting plastic recycling tech like crazy.

1 Like

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.