Я пытаюсь построить тепловую карту, используя geom_tile () в R, однако плитки на моем графике не имеют квадратной формы, как здесь, где-то здесь Ожидаемый формат вывода: (https://twitter.com/jakekaupp/status/1092974571383386112).
Плитка похожа на прямоугольник, а не на квадраты. Я попытался с помощью cord_equal (), изменения размера, ширины и т. Д. c, но ничего не получается.
library(tidyverse)
library(office)
office <- schrute::theoffice
top_3_lines_per_episode <- office %>%
group_by(season,episode,episode_name,imdb_rating) %>%
count(character) %>%
top_n(3, n) %>% ungroup() %>%
mutate(episode_id = group_indices(., season,episode,episode_name,imdb_rating))
top_3_lines <- top_3_lines_per_episode %>%
mutate(episode_mod = episode_id + 3 * parse_number(season)) %>%
group_by(season) %>%
mutate(mid = mean(episode_mod)) %>%
group_by(character) %>%
add_count(name="total_lines") %>% ungroup() %>%
mutate(character=fct_lump(character,10),
character=fct_reorder(character,total_lines))
ggplot(top_3_lines, aes(x = as.factor(episode_mod), y = character, fill = imdb_rating)) +
geom_tile(color = "white", size = 0.05) +
#coord_equal(ratio = 200) +
labs(x = NULL, y = NULL, title = "The Office, Chacracters with top 3 lines") +
scale_fill_viridis(discrete = FALSE, name = "IMDB rating") +
theme(axis.text.y =element_text(size=8,face="bold"),
axis.text.x =element_blank())