首页 > 解决方案 > ggplot2 - 按区域大小范围排序区域图

问题描述

我有一个关于按大小订购区域图的问题。我想从大尺寸到小尺寸排序。如,

在此处输入图像描述

这是我的代码

library(ggplot2)

ggplot(data,aes(x = DT, y = value,group=DMG,color=DMG)) +
  geom_smooth(method = "lm",
              se = FALSE,
              formula = 'y ~ x',
              span = 0.8) +
  stat_smooth(se=FALSE, geom="area",
              method = "lm",
              position = position_stack(reverse = T),
              span = 0.75,aes(fill=DMG))

使用position_stack(reverse = T),只有一个区域是错误的排序(粉红色区域)

这是一个输入数据 data.csv

#str(dmg_all)
'data.frame':   1625 obs. of  3 variables:
 $ DT   : num  0 0.19 0.284 0.362 0.397 ...
 $ DMG  : Factor w/ 5 levels "AGR_DMG","LB_DMG",..: 1 1 1 1 1 1 1 1 1 1 ...
 $ value: num  0 0.0282 0.0407 0.0503 0.0533 ...

#dmg_all$DMG
Levels: AGR_DMG LB_DMG MORT_DMG ED_DMG HPP_DMG

在此处输入图像描述

你能指导我做什么吗?太感谢了。

标签: rggplot2area-chart

解决方案


推荐阅读