0

I'm trying to create circular heatmap with ggplot2. I'd like to have it look like a donut with an empty hole in the middle but i can do it. Can we help me ?

library(reshape)
library(ggplot2)
library(plyr)
library (readxl)
nba <-read_excel("C:/Users/iman0/Desktop/Essai R filtre.xlsx")
nba$Name <- with(nba, reorder(Name, GES))
Limey
  • 10,234
  • 2
  • 12
  • 32
Stage
  • 35
  • 4
  • 2
    try and turn this into a more [reproducible](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) example – neuroandstats Apr 28 '21 at 02:55

1 Answers1

0

On StackOverflow you are encouraged to show your own efforts to solve the problem. This helps to guide answers and helps to determine the level of explanation you require. Without more details, all I can provide is an example:

library(tidyverse)
devtools::install_github("abresler/nbastatR")
library(nbastatR)
library(ggrepel)

options(scipen = 1000000)

salaries <- nba_insider_salaries(assume_player_opt_out = T,
                                       assume_team_doesnt_exercise = T,
                                       return_message = T)
salaries %>% 
  group_by(nameTeam) %>% 
  filter(str_detect(slugSeason, "2020")) %>% 
  select(nameTeam, value) %>%
  summarise(total = sum(value)) %>% 
  mutate(perc = total / sum(total)) %>%
  mutate(ymax = cumsum(perc),
         ymin = c(0, head(ymax, n=-1))) %>%
  mutate(labelPosition = (ymax + ymin) / 2) %>%
  rename(`Team Name` = nameTeam,
         `Total Salaries` = total) %>% 
  ggplot(aes(ymax = ymax, ymin = ymin, xmax = 4, xmin = 3)) +
  geom_rect(aes(fill = `Total Salaries`)) +
  geom_label_repel(x = 4, aes(y = labelPosition,
                             label = `Team Name`),
                  min.segment.length = 0, size = 2, force = 3) +
  coord_polar(theta = "y") +
  xlim(c(2, 4)) +
  ggtitle("NBA Total Salaries", subtitle = "2020 Season") +
  scale_fill_continuous(labels = scales::dollar) +
  theme_void()

example_1.png

Does this answer your question?

jared_mamrot
  • 22,354
  • 4
  • 21
  • 46
  • Hello Jared, Thank you very much for taking the time to respond ! I am a beginner on R. And I didn't really know how to start my script – Stage Apr 28 '21 at 21:06
  • Hello Jared, Can I have your opinion ? – Stage Apr 29 '21 at 14:46
  • This package appears to be what you are looking for: https://jokergoo.github.io/circlize_book/book/ – jared_mamrot Apr 29 '21 at 22:11
  • Thank you very much for your help but how can I add it? I read the whole of your article but I failed to reproduce the figure in my R studio Do I have to start my script over from the beginning? I tried without results (R studio indicates an error) – Stage May 01 '21 at 01:13
  • https://stackoverflow.com/questions/67342060/use-circos-function-in-circos – Stage May 01 '21 at 01:19