冲积地块中的小值,其中减小字体大小似乎不是解决方案

Posted

技术标签:

【中文标题】冲积地块中的小值,其中减小字体大小似乎不是解决方案【英文标题】:Small values in alluvial plot where decreasing fontsize does not seem to be the solution 【发布时间】:2021-07-13 16:48:17 【问题描述】:

我有一个问题,我在处理“更糟”类别中的小计数时遇到了一些问题。进一步减小字体大小会降低可读性(改变垂直高度也不是我的解决方案)。有人对呈现类别有一个巧妙的想法(例如带有文本框的箭头,但是如何?)

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)

【讨论】:

以上是关于冲积地块中的小值,其中减小字体大小似乎不是解决方案的主要内容,如果未能解决你的问题,请参考以下文章

在冲积地块中交换颜色

冲积地块边距

具有 2 个不同来源但有一个收敛/共享变量的冲积地块 [R]

减小 graphviz 生成的图形的大小(如面积)

减小.ttf字体大小的方法?

如何减小字体真棒图标的大小?