r - 面积图显示较大的值低于较小的值

标签 r ggplot2 plotly

我想显示包含实际值和累积值的面积图。虽然我希望实际值显示得低于累积值,但相反的情况却发生了,并且图表也以一种非常奇怪的方式显示。

Tar<-structure(list(Week = structure(c(1L, 1L, 15L, 15L, 20L, 20L, 
8L, 8L, 3L, 3L, 18L, 18L, 16L, 16L, 14L, 14L, 5L, 5L, 14L, 14L, 
15L, 15L, 8L, 8L, 10L, 10L, 19L, 19L, 5L, 5L, 17L, 17L, 20L, 
20L, 18L, 18L, 18L, 18L, 2L, 2L, 3L, 3L, 8L, 8L, 20L, 20L, 20L, 
20L, 7L, 7L, 5L, 5L, 2L, 2L, 18L, 18L, 16L, 16L, 7L, 7L, 20L, 
20L, 17L, 17L, 20L, 20L, 20L, 20L, 5L, 5L, 15L, 15L, 16L, 16L, 
6L, 6L, 14L, 14L, 20L, 20L, 15L, 15L, 8L, 8L, 18L, 18L, 14L, 
14L, 16L, 16L, 18L, 18L, 5L, 5L, 5L, 5L, 20L, 20L, 20L, 20L, 
20L, 20L, 1L, 1L, 16L, 16L, 7L, 7L, 9L, 9L, 15L, 15L, 18L, 18L, 
20L, 20L, 15L, 15L, 3L, 3L, 19L, 19L, 14L, 14L, 17L, 17L, 10L, 
10L, 20L, 20L, 9L, 9L, 18L, 18L, 18L, 18L, 14L, 14L, 5L, 5L, 
18L, 18L, 14L, 14L, 9L, 9L, 17L, 17L, 16L, 16L, 9L, 9L, 10L, 
10L, 14L, 14L, 15L, 15L, 7L, 7L, 20L, 20L, 20L, 20L, 10L, 10L, 
18L, 18L, 10L, 10L, 20L, 20L, 11L, 11L, 8L, 8L, 17L, 17L, 15L, 
15L, 20L, 20L, 15L, 15L, 11L, 11L, 8L, 8L, 5L, 5L, 16L, 16L, 
7L, 7L, 14L, 14L, 15L, 15L, 14L, 14L, 17L, 17L, 14L, 14L, 20L, 
20L, 14L, 14L, 15L, 15L, 14L, 14L, 5L, 5L, 19L, 19L, 18L, 18L, 
14L, 14L, 3L, 3L, 14L, 14L, 8L, 8L, 14L, 14L, 15L, 15L, 3L, 3L, 
20L, 20L, 5L, 5L, 20L, 20L, 17L, 17L, 19L, 19L, 8L, 8L, 8L, 8L, 
9L, 9L, 14L, 14L, 3L, 3L, 20L, 20L, 19L, 19L, 17L, 17L, 3L, 3L, 
14L, 14L, 1L, 1L, 16L, 16L, 18L, 18L, 18L, 18L, 20L, 20L, 18L, 
18L, 16L, 16L, 16L, 16L, 7L, 7L, 15L, 15L, 20L, 20L, 17L, 17L, 
8L, 8L, 16L, 16L, 15L, 15L, 3L, 3L, 19L, 19L, 15L, 15L, 17L, 
17L, 2L, 2L, 20L, 20L, 10L, 10L, 16L, 16L, 14L, 14L, 8L, 8L, 
18L, 18L, 6L, 6L, 10L, 10L, 17L, 17L, 3L, 3L, 17L, 17L, 18L, 
18L, 18L, 18L, 14L, 14L, 15L, 15L, 14L, 14L, 14L, 14L, 18L, 18L, 
16L, 16L, 14L, 14L, 4L, 4L, 18L, 18L, 13L, 13L, 6L, 6L, 14L, 
14L, 15L, 15L, 14L, 14L, 3L, 3L, 16L, 16L, 18L, 18L, 4L, 4L, 
2L, 2L, 8L, 8L, 3L, 3L, 14L, 14L, 5L, 5L, 18L, 18L, 8L, 8L, 19L, 
19L, 17L, 17L, 14L, 14L, 17L, 17L, 20L, 20L, 17L, 17L, 15L, 15L, 
18L, 18L, 10L, 10L, 2L, 2L, 15L, 15L, 8L, 8L, 14L, 14L, 16L, 
16L, 14L, 14L, 5L, 5L, 19L, 19L, 5L, 5L, 4L, 4L, 17L, 17L, 6L, 
6L, 6L, 6L, 4L, 4L, 13L, 13L, 18L, 18L, 2L, 2L, 17L, 17L, 14L, 
14L, 20L, 20L, 6L, 6L, 3L, 3L, 15L, 15L, 18L, 18L, 6L, 6L, 3L, 
3L, 20L, 20L, 11L, 11L, 20L, 20L, 16L, 16L, 8L, 8L, 18L, 18L, 
7L, 7L, 14L, 14L, 1L, 1L, 4L, 4L, 20L, 20L, 20L, 20L, 8L, 8L, 
18L, 18L, 1L, 1L, 14L, 14L, 4L, 4L, 14L, 14L, 18L, 18L, 4L, 4L, 
5L, 5L, 6L, 6L, 20L, 20L, 2L, 2L, 8L, 8L, 18L, 18L, 18L, 18L, 
15L, 15L, 7L, 7L, 17L, 17L, 20L, 20L, 8L, 8L, 5L, 5L, 16L, 16L, 
13L, 13L, 12L, 12L, 16L, 16L, 17L, 17L, 20L, 20L, 9L, 9L, 4L, 
4L, 14L, 14L, 15L, 15L, 20L, 20L, 5L, 5L, 18L, 18L, 4L, 4L, 16L, 
16L, 2L, 2L, 6L, 6L, 7L, 7L, 3L, 3L, 13L, 13L, 13L, 13L, 20L, 
20L, 18L, 18L, 17L, 17L, 14L, 14L, 18L, 18L, 12L, 12L, 7L, 7L, 
20L, 20L, 4L, 4L, 13L, 13L, 6L, 6L, 5L, 5L, 6L, 6L, 20L, 20L, 
20L, 20L, 14L, 14L, 6L, 6L, 5L, 5L, 4L, 4L, 2L, 2L, 17L, 17L, 
9L, 9L, 15L, 15L, 16L, 16L, 18L, 18L, 16L, 16L, 4L, 4L, 6L, 6L, 
13L, 13L, 17L, 17L, 8L, 8L, 17L, 17L, 7L, 7L, 5L, 5L, 15L, 15L, 
1L, 1L, 6L, 6L, 4L, 4L, 20L, 20L, 5L, 5L, 3L, 3L, 6L, 6L, 20L, 
20L, 13L, 13L, 8L, 8L, 18L, 18L, 4L, 4L, 7L, 7L, 5L, 5L, 6L, 
6L, 16L, 16L, 18L, 18L, 20L, 20L, 20L, 20L, 20L, 20L, 6L, 6L, 
13L, 13L, 5L, 5L, 16L, 16L, 17L, 17L, 6L, 6L, 13L, 13L, 8L, 8L, 
15L, 15L, 6L, 6L, 4L, 4L, 8L, 8L, 13L, 13L, 3L, 3L, 6L, 6L, 20L, 
20L, 18L, 18L, 6L, 6L, 13L, 13L, 14L, 14L, 11L, 11L, 8L, 8L, 
7L, 7L, 4L, 4L, 16L, 16L, 16L, 16L, 17L, 17L, 1L, 1L, 5L, 5L, 
17L, 17L, 5L, 5L, 20L, 20L, 20L, 20L, 4L, 4L, 6L, 6L, 15L, 15L, 
7L, 7L, 18L, 18L, 17L, 17L, 17L, 17L, 3L, 3L, 5L, 5L, 18L, 18L, 
16L, 16L, 18L, 18L, 18L, 18L, 20L, 20L, 6L, 6L, 16L, 16L, 2L, 
2L, 8L, 8L, 20L, 20L, 16L, 16L, 6L, 6L, 8L, 8L, 3L, 3L, 15L, 
15L, 16L, 16L, 19L, 19L, 16L, 16L, 18L, 18L, 5L, 5L, 17L, 17L, 
4L, 4L, 6L, 6L, 16L, 16L, 6L, 6L, 20L, 20L, 17L, 17L, 7L, 7L, 
7L, 7L, 2L, 2L, 18L, 18L, 18L, 18L, 20L, 20L, 7L, 7L, 16L, 16L, 
2L, 2L, 15L, 15L, 20L, 20L, 15L, 15L, 4L, 4L, 5L, 5L, 16L, 16L, 
6L, 6L, 19L, 19L, 3L, 3L, 18L, 18L, 6L, 6L, 7L, 7L, 18L, 18L, 
20L, 20L, 17L, 17L, 18L, 18L, 6L, 6L, 9L, 9L), .Label = c("1", 
"2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", 
"14", "15", "16", "17", "18", "19", "20"), class = "factor"), 
    Type = c("Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target", "Cumilative target", 
    "Actual target", "Cumilative target", "Actual target"), Count = c(5, 
    7, 323, 29, 448, 52, 148, 25, 28, 19, 398, 47, 348, 33, 298, 
    37, 73, 27, 298, 37, 323, 29, 148, 25, 198, 8, 423, 10, 73, 
    27, 373, 31, 448, 52, 398, 47, 398, 47, 13, 12, 28, 19, 148, 
    25, 448, 52, 448, 52, 123, 18, 73, 27, 13, 12, 398, 47, 348, 
    33, 123, 18, 448, 52, 373, 31, 448, 52, 448, 52, 73, 27, 
    323, 29, 348, 33, 98, 29, 298, 37, 448, 52, 323, 29, 148, 
    25, 398, 47, 298, 37, 348, 33, 398, 47, 73, 27, 73, 27, 448, 
    52, 448, 52, 448, 52, 5, 7, 348, 33, 123, 18, 173, 8, 323, 
    29, 398, 47, 448, 52, 323, 29, 28, 19, 423, 10, 298, 37, 
    373, 31, 198, 8, 448, 52, 173, 8, 398, 47, 398, 47, 298, 
    37, 73, 27, 398, 47, 298, 37, 173, 8, 373, 31, 348, 33, 173, 
    8, 198, 8, 298, 37, 323, 29, 123, 18, 448, 52, 448, 52, 198, 
    8, 398, 47, 198, 8, 448, 52, 223, 4, 148, 25, 373, 31, 323, 
    29, 448, 52, 323, 29, 223, 4, 148, 25, 73, 27, 348, 33, 123, 
    18, 298, 37, 323, 29, 298, 37, 373, 31, 298, 37, 448, 52, 
    298, 37, 323, 29, 298, 37, 73, 27, 423, 10, 398, 47, 298, 
    37, 28, 19, 298, 37, 148, 25, 298, 37, 323, 29, 28, 19, 448, 
    52, 73, 27, 448, 52, 373, 31, 423, 10, 148, 25, 148, 25, 
    173, 8, 298, 37, 28, 19, 448, 52, 423, 10, 373, 31, 28, 19, 
    298, 37, 5, 7, 348, 33, 398, 47, 398, 47, 448, 52, 398, 47, 
    348, 33, 348, 33, 123, 18, 323, 29, 448, 52, 373, 31, 148, 
    25, 348, 33, 323, 29, 28, 19, 423, 10, 323, 29, 373, 31, 
    13, 12, 448, 52, 198, 8, 348, 33, 298, 37, 148, 25, 398, 
    47, 98, 29, 198, 8, 373, 31, 28, 19, 373, 31, 398, 47, 398, 
    47, 298, 37, 323, 29, 298, 37, 298, 37, 398, 47, 348, 33, 
    298, 37, 48, 19, 398, 47, 273, 12, 98, 29, 298, 37, 323, 
    29, 298, 37, 28, 19, 348, 33, 398, 47, 48, 19, 13, 12, 148, 
    25, 28, 19, 298, 37, 73, 27, 398, 47, 148, 25, 423, 10, 373, 
    31, 298, 37, 373, 31, 448, 52, 373, 31, 323, 29, 398, 47, 
    198, 8, 13, 12, 323, 29, 148, 25, 298, 37, 348, 33, 298, 
    37, 73, 27, 423, 10, 73, 27, 48, 19, 373, 31, 98, 29, 98, 
    29, 48, 19, 273, 12, 398, 47, 13, 12, 373, 31, 298, 37, 448, 
    52, 98, 29, 28, 19, 323, 29, 398, 47, 98, 29, 28, 19, 448, 
    52, 223, 4, 448, 52, 348, 33, 148, 25, 398, 47, 123, 18, 
    298, 37, 5, 7, 48, 19, 448, 52, 448, 52, 148, 25, 398, 47, 
    5, 7, 298, 37, 48, 19, 298, 37, 398, 47, 48, 19, 73, 27, 
    98, 29, 448, 52, 13, 12, 148, 25, 398, 47, 398, 47, 323, 
    29, 123, 18, 373, 31, 448, 52, 148, 25, 73, 27, 348, 33, 
    273, 12, 248, 2, 348, 33, 373, 31, 448, 52, 173, 8, 48, 19, 
    298, 37, 323, 29, 448, 52, 73, 27, 398, 47, 48, 19, 348, 
    33, 13, 12, 98, 29, 123, 18, 28, 19, 273, 12, 273, 12, 448, 
    52, 398, 47, 373, 31, 298, 37, 398, 47, 248, 2, 123, 18, 
    448, 52, 48, 19, 273, 12, 98, 29, 73, 27, 98, 29, 448, 52, 
    448, 52, 298, 37, 98, 29, 73, 27, 48, 19, 13, 12, 373, 31, 
    173, 8, 323, 29, 348, 33, 398, 47, 348, 33, 48, 19, 98, 29, 
    273, 12, 373, 31, 148, 25, 373, 31, 123, 18, 73, 27, 323, 
    29, 5, 7, 98, 29, 48, 19, 448, 52, 73, 27, 28, 19, 98, 29, 
    448, 52, 273, 12, 148, 25, 398, 47, 48, 19, 123, 18, 73, 
    27, 98, 29, 348, 33, 398, 47, 448, 52, 448, 52, 448, 52, 
    98, 29, 273, 12, 73, 27, 348, 33, 373, 31, 98, 29, 273, 12, 
    148, 25, 323, 29, 98, 29, 48, 19, 148, 25, 273, 12, 28, 19, 
    98, 29, 448, 52, 398, 47, 98, 29, 273, 12, 298, 37, 223, 
    4, 148, 25, 123, 18, 48, 19, 348, 33, 348, 33, 373, 31, 5, 
    7, 73, 27, 373, 31, 73, 27, 448, 52, 448, 52, 48, 19, 98, 
    29, 323, 29, 123, 18, 398, 47, 373, 31, 373, 31, 28, 19, 
    73, 27, 398, 47, 348, 33, 398, 47, 398, 47, 448, 52, 98, 
    29, 348, 33, 13, 12, 148, 25, 448, 52, 348, 33, 98, 29, 148, 
    25, 28, 19, 323, 29, 348, 33, 423, 10, 348, 33, 398, 47, 
    73, 27, 373, 31, 48, 19, 98, 29, 348, 33, 98, 29, 448, 52, 
    373, 31, 123, 18, 123, 18, 13, 12, 398, 47, 398, 47, 448, 
    52, 123, 18, 348, 33, 13, 12, 323, 29, 448, 52, 323, 29, 
    48, 19, 73, 27, 348, 33, 98, 29, 423, 10, 28, 19, 398, 47, 
    98, 29, 123, 18, 398, 47, 448, 52, 373, 31, 398, 47, 98, 
    29, 173, 8)), row.names = c(NA, -858L), class = "data.frame")
    
library(ggplot2)
library(dplyr)
library(plotly)
p <-
    ggplot(Tar, aes(x = Week, y = Count, fill = Type))+
    geom_area(alpha = 0.6 , size = 0.5, colour = "white", stat = "identity", orientation = "x") +
    labs(fill = NULL)+
    theme(legend.position = "bottom")
p <- p+labs(title = "Figure 1: Weekly Cumulative Projected Enrollment vs Weekly Cumulative Actual Enrollment",
            subtitle = "Cum Weekly Projected Enrollment/Cum Weekly Actual Enrollment")


# not printed
ggplotly(p)

它应该是这样的:

enter image description here

最佳答案

数据中每个组和周都有重复的条目,因此看起来很困惑。此外,为了不堆叠当前和累积(这是相当误导的),您可以设置 position = "identity"。我通过因子转换将实际值带到前面,但可以按照您的喜好进行处理。

library(ggplot2)
library(dplyr)
library(plotly)
clean_data <- Tar %>% 
  distinct() %>% 
  mutate(Type = ordered(Type, levels = unique(Type)[2:1]))

p <- ggplot(clean_data, aes(x = Week, y = Count, fill = Type, group = Type)) +
  geom_area(alpha = 0.6 , size = 0.5, colour = "white", position = "identity", orientation = "x") +
  labs(fill = NULL)+
  theme(legend.position = "bottom")
p <- p+labs(title = "Figure 1: Weekly Cumulative Projected Enrollment vs Weekly Cumulative Actual Enrollment",
            subtitle = "Cum Weekly Projected Enrollment/Cum Weekly Actual Enrollment")

p
# not printed
ggplotly(p)

enter image description here

关于r - 面积图显示较大的值低于较小的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69178320/

相关文章:

r - 调整连续变量的图例宽度

r - 如何计算ggplot2绘制的椭圆面积?

r - flextable:嵌入 ggpplots 使用来自 2 列的数据和列表(用于比较)作为每行的单个图

python - plotly 指标数字舍入

python - Plotly:如何重命名 plotly 表达堆叠条形图的图例元素?

R plotly 3d条形图

r - 计算 R 中每行中特定列的下 3 行的最大值

r - 将时间戳(以微秒为单位)转换为 r 中的数据和时间

R - (Tidyverse) 根据列整数将一行变成多行

JavaScript 无法在 Shiny 的模态中工作