Home > front end >  R - Squared Pie chart
R - Squared Pie chart

Time:10-18

Need help to get my pie chart displayed like this:

enter image description here

As you can see a square proportion is drawn using a given percentage. I'm trying to plot an industry's weigths (10 variables).

Here is my DF:

     BUSD     USDC      DAI    GEMINI      HUSD       PAX     STASIS       UST     USDT       TRU
1 11.70257 37.16381 4.529632 0.1128532 0.1778291 0.6171099 0.02256854 0.3773179 44.49382 0.8024782

I'm open to any solutions, but i need percentages and TitleS inside each box.

Ty

CodePudding user response:

This is called a treemap, you can do one with the treemapify library and ggplot2:

library(ggplot2)
library(tidyr)
#install.packages("treemapify")
library(treemapify)

pivot_longer(df, everything()) %>% 
  ggplot(aes(area = value, fill = name))  
  geom_treemap()  
  geom_treemap_text(aes(label = paste(name, paste0(round(value, 2), "%"), sep = "\n")), colour = "white")  
  theme(legend.position = "none")

enter image description here

  • Related