2 votes

Existe-t-il un moyen de mieux intégrer cette parcelle de densité dans le cadre ?

Dput

Voici le résultat de mes données :

work <- structure(list(Mins_Work = c(435L, 350L, 145L, 135L, 15L, 60L, 
                                     60L, 390L, 395L, 395L, 315L, 80L, 580L, 175L, 545L, 230L, 435L, 
                                     370L, 255L, 515L, 330L, 65L, 115L, 550L, 420L, 45L, 266L, 196L, 
                                     198L, 220L, 17L, 382L, 0L, 180L, 343L, 207L, 263L, 332L, 0L, 
                                     0L, 259L, 417L, 282L, 685L, 517L, 111L, 64L, 466L, 499L, 460L, 
                                     269L, 300L, 427L, 301L, 436L, 342L, 229L, 379L, 102L, 146L, NA, 
                                     94L, 345L, 73L, 204L, 512L, 113L, 135L, 458L, 493L, 552L, 108L, 
                                     335L, 395L, 508L, 546L, 396L, 159L, 325L, 747L, 650L, 377L, 461L, 
                                     669L, 186L, 220L, 410L, 708L, 409L, 515L, 413L, 166L, 451L, 660L, 
                                     177L, 192L, 191L, 461L, 637L, 297L, 601L, 586L, 270L, 479L, 0L, 
                                     480L, 397L, 174L, 111L, 0L, 610L, 332L, 345L, 423L, 160L, 611L, 
                                     0L, 345L, 550L, 324L, 427L, 505L, 632L, 560L, 230L, 495L, 235L, 
                                     522L, 654L, 465L, 377L, 260L, 572L, 612L, 594L, 624L, 237L, 0L, 
                                     38L, 409L, 634L, 292L, 706L, 399L, 568L, 0L, 694L, 298L, 616L, 
                                     553L, 581L, 423L, 636L, 623L, 338L, 345L, 521L, 438L, 504L, 600L, 
                                     616L, 656L, 285L, 474L, 688L, 278L, 383L, 535L, 363L, 470L, 457L, 
                                     303L, 123L, 363L, 329L, 513L, 524L, NA), Month_Name = c("September", 
                                                                                             "September", "September", "September", "September", "September", 
                                                                                             "September", "September", "September", "September", "September", 
                                                                                             "September", "September", "September", "September", "September", 
                                                                                             "September", "September", "September", "September", "September", 
                                                                                             "September", "September", "September", "September", "September", 
                                                                                             "September", "September", "September", "September", "October", 
                                                                                             "October", "October", "October", "October", "October", "October", 
                                                                                             "October", "October", "October", "October", "October", "October", 
                                                                                             "October", "October", "October", "October", "October", "October", 
                                                                                             "October", "October", "October", "October", "October", "October", 
                                                                                             "October", "October", "October", "October", "October", "October", 
                                                                                             "November", "November", "November", "November", "November", "November", 
                                                                                             "November", "November", "November", "November", "November", "November", 
                                                                                             "November", "November", "November", "November", "November", "November", 
                                                                                             "November", "November", "November", "November", "November", "November", 
                                                                                             "November", "November", "November", "November", "November", "November", 
                                                                                             "December", "December", "December", "December", "December", "December", 
                                                                                             "December", "December", "December", "December", "December", "December", 
                                                                                             "December", "December", "December", "December", "December", "December", 
                                                                                             "December", "December", "December", "December", "December", "December", 
                                                                                             "December", "December", "December", "December", "December", "December", 
                                                                                             "December", "January", "January", "January", "January", "January", 
                                                                                             "January", "January", "January", "January", "January", "January", 
                                                                                             "January", "January", "January", "January", "January", "January", 
                                                                                             "January", "January", "January", "January", "January", "January", 
                                                                                             "January", "January", "January", "January", "January", "January", 
                                                                                             "January", "January", "February", "February", "February", "February", 
                                                                                             "February", "February", "February", "February", "February", "February", 
                                                                                             "February", "February", "February", "February", "February", "February", 
                                                                                             "February", "February", "February", "February", "February", "February", 
                                                                                             "February", "February", "")), class = "data.frame", row.names = c(NA, 
                                                                                                                                                               -178L))

Numéro

Jusqu'à présent, j'ai conçu ce code pour réaliser un graphique de densité de crêtes :

# Load libraries:
library(tidyverse)
library(ggridges)
library(patchwork)
library(viridis)
library(hrbrthemes)
library(gapminder)
theme_set(theme_bw())

# Filter data and create plot:
work %>% 
  filter(Month_Name %in% c("September",
                           "October",
                           "November",
                           "December",
                           "January",
                           "February")) %>% 
  ggplot(aes(x=Mins_Work,
           y=Month_Name,
           fill = ..x..))+
  geom_density_ridges_gradient(scale = 3,
                               rel_min_height = 0.01,
                               alpha = .5)+
  scale_fill_viridis(option = "B")+
  labs(title = "Distribution of Recorded Work by Month",
       x="Minutes of Recorded Work",
       y="Month")

Cependant, si le tracé semble correct pour l'essentiel, la partie supérieure semble être un peu coupée par le cadre :

enter image description here

Existe-t-il un moyen d'ajuster la parcelle pour qu'elle s'adapte mieux ou ne soit pas coupée de cette façon ? Ou y a-t-il une limite au nombre de tracés de densité que l'on peut faire tenir dans un cadre ?

2voto

Peter Points 4202

Augmentez l'espace entre le tracé et l'axe à l'aide de scale_y_discrete(expand = expansion(mult = c(0.05, 0.7))) . Le deuxième élément de la mult L'argument contrôle les limites supérieures : fixé à une valeur élevée pour illustrer le propos - fixé pour répondre à vos exigences esthétiques.

theme_set(theme_bw())

# Filter data and create plot:
work %>% 
  filter(Month_Name %in% c("September",
                           "October",
                           "November",
                           "December",
                           "January",
                           "February")) %>% 
  ggplot(aes(x=Mins_Work,
             y=Month_Name,
             fill = ..x..))+
  geom_density_ridges_gradient(scale = 3,
                               rel_min_height = 0.01,
                               alpha = .5)+
  scale_fill_viridis(option = "B")+
  scale_y_discrete(expand = expansion(mult = c(0.05, 0.7)))+
  labs(title = "Distribution of Recorded Work by Month",
       x="Minutes of Recorded Work",
       y="Month")

Créé le 2022-02-24 par le paquet reprex (v2.0.1)

Prograide.com

Prograide est une communauté de développeurs qui cherche à élargir la connaissance de la programmation au-delà de l'anglais.
Pour cela nous avons les plus grands doutes résolus en français et vous pouvez aussi poser vos propres questions ou résoudre celles des autres.

Powered by:

X