Небольшие значения на аллювиальном графике, когда уменьшение размера шрифта не является решением

У меня есть вопрос, в связи с которым у меня возникли проблемы с небольшими счетами в категории «Хуже». Еще большее уменьшение размера шрифта ухудшит читаемость (изменение высоты по вертикали также не является решением для меня). Есть ли у кого-нибудь гениальная идея представления категории (например, стрелка с текстовым полем, но как?)

      library(alluvial)
library(ggalluvial)
library(ggplot2)

Shortterm<-c("Healed","Impoved","Same","Worse","Healed","Improved","Same","Worse","Healed","Improved","Same","Worse")
Longterm<-c("Healed","Healed","Healed","Healed","Improved","Improved","Improved","Improved","Worse","Worse","Worse","Worse")
Frequence<-c(28,2,0,1,14,6,3,0,1,1,0,0)
Order<-c(0,0,0,0,1,1,1,1,2,2,2,2)
Improved<-c("Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","No","No","No","No")

output<-data.frame(Shortterm,Longterm,Frequence,Order,Improved)
output$Improved <- factor(output$Improved, levels = c("Yes", "No"))

ggplot(data = output,
       aes(axis1 = Shortterm, axis2 = Longterm,
           y = Frequence)) +
  scale_x_discrete(limits = c("Short-term \n ~ 6 months", "Long-term \n ~ 15 years"),expand = c(.2, .05),position="bottom") +
  scale_y_continuous(label = scales::percent_format(scale = 100 /n_id),breaks=c(0,1/4*n_id,1/2*n_id,3/4*n_id,n_id)) +
  geom_alluvium(aes(fill = Improved)) +
  geom_stratum() +
  geom_text(stat = "stratum", aes(label = after_stat(stratum))) +
  scale_fill_manual(values = c("green", "red"))+
  theme_minimal()

1 ответ

Я нашел ответ:

      Shortterm<-c("Healed","Improved","Same"," ","Healed","Improved","Same"," ","Healed","Improved","Same"," ")
Longterm<-c("Healed","Healed","Healed","Healed","Improved","Improved","Improved","Improved","Worse","Worse","Worse","Worse")
Frequence<-c(28,2,0,1,14,6,3,0,1,1,0,0)
Order<-c(0,0,0,0,1,1,1,1,2,2,2,2)
Improved<-c("Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","No","No","No","No")

output<-data.frame(Shortterm,Longterm,Frequence,Order,Improved)
output$Improved <- factor(output$Improved, levels = c("Yes", "No"))
output$Shortterm <- factor(output$Shortterm, levels = c("Healed","Same","Improved"," "))
output$Longterm  <- factor(output$Longterm,  levels = c("Healed","Same","Improved","Worse"))

n_id <- sum(output$Frequence)
ggplot(data = output,
       aes(axis1 = Shortterm, axis2 = Longterm,
           y = Frequence)) +
  scale_x_discrete(limits = c("Short-term \n ~ 6 months", "Long-term \n ~ 15 years"),expand = c(.2, .05),position="bottom") +
  scale_y_continuous(label = scales::percent_format(scale = 100 /n_id),breaks=c(0,1/4*n_id,1/2*n_id,3/4*n_id,n_id)) +
  geom_alluvium(aes(fill = Improved)) +
  geom_stratum() +
  geom_text(stat = "stratum", aes(label = after_stat(stratum)),size=3) +
  scale_fill_manual(values = c("green", "red"))+
  theme_minimal() +
  ylab("Operated patients") + xlab("")+ theme(axis.text.x = element_text(face="bold",size=14))+
  annotate(
    geom = "curve", x = 1, y = 0.4, xend = 1.05, yend = -2, 
    curvature = .3, arrow = arrow(length = unit(2, "mm"))
  )+
  annotate(geom = "text", x = 1.07, y = -2, label = "Worse", hjust = "left",size=3)

Другие вопросы по тегам