Hi people,
I'm trying to construct a graphic with ggridges as following:
But, for each element in the y-axis I have different values. For instance the amount of A624 is 5.504 and for A674 I have just 21.
I'd like to control the heigth of the ridges by thes amount to make proportional. That means the last one would be less tall than the first one.
How could I do this? Thank for those who can help
library(tidyverse)
library(ggridges)
library(viridis)
#
dt <- read_csv("https://raw.githubusercontent.com/ronycoelho/databases/master/data_councils.csv")
# Count each element
councils_qt <- dt %>%
count(councils) %>%
arrange(desc(n)) %>%
mutate (councils_qt = paste0(councils, " (", n, ")"))
# Join to make labels
dt <- dt %>%
full_join(councils_qt)
# Plot
plot <- ggplot(dt,
aes(x=years, y=reorder(councils_qt, -years, FUN = mean)))+
geom_density_ridges(aes(fill=reorder(councils_qt, -years, FUN = mean)),
show.legend = F, alpha = .7, panel_scaling = F) +
scale_fill_viridis_d(option = "B", direction = -1,
begin = .1, end = .9)+
scale_x_continuous(limits = c(1988, 2018),
breaks = c(1990, 1994, 1998, 2002, 2006, 2010, 2014))+
#scale_y_discrete(labels = c())+
geom_vline(xintercept = c(1990, 1994, 1998, 2002, 2006, 2010, 2014), linetype= "dotdash") +
ylab("") + xlab("")+
theme_classic()+
theme(axis.text.x = element_text(size = 14, face = "bold"),
axis.text.y = element_text(size = 14, face = "bold"))
plot