我有如下数据:(对不起,大样本,但使情节发生在情节上的可能性很小)
df <- structure(list(predictor = structure(c(18L, 18L, 18L, 18L, 18L,
18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 13L, 13L, 13L, 13L,
13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 11L, 11L, 11L,
11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 41L, 41L,
41L, 41L, 41L, 41L, 41L, 41L, 41L, 41L, 41L, 41L, 41L, 41L, 15L,
15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 35L,
35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L,
39L, 39L, 39L, 39L, 39L, 39L, 39L, 39L, 39L, 39L, 39L, 39L, 39L,
39L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L,
27L, 27L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 43L, 43L, 43L, 43L, 43L, 43L, 43L, 43L, 43L, 43L, 43L, 43L,
43L, 43L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L,
14L, 14L, 14L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L,
37L, 37L, 37L, 37L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L,
23L, 23L, 23L, 23L, 23L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L,
31L, 31L, 31L, 31L, 31L, 31L, 25L, 25L, 25L, 25L, 25L, 25L, 25L,
25L, 25L, 25L, 25L, 25L, 25L, 25L, 19L, 19L, 19L, 19L, 19L, 19L,
19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 34L, 34L, 34L, 34L, 34L,
34L, 34L, 34L, 34L, 34L, 34L, 34L, 34L, 34L, 28L, 28L, 28L, 28L,
28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 40L, 40L, 40L,
40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 36L, 36L,
36L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 30L, 30L,
30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 21L,
21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L,
20L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 33L,
33L, 33L, 33L, 33L, 33L, 33L, 33L, 33L, 33L, 33L, 33L, 33L, 33L,
22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L,
22L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L,
26L, 26L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L,
12L, 12L, 12L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L,
29L, 29L, 29L, 29L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L,
24L, 24L, 24L, 24L, 24L, 38L, 38L, 38L, 38L, 38L, 38L, 38L, 38L,
38L, 38L, 38L, 38L, 38L, 38L, 16L, 16L, 16L, 16L, 16L, 16L, 16L,
16L, 16L, 16L, 16L, 16L, 16L, 16L, 42L, 42L, 42L, 42L, 42L, 42L,
42L, 42L, 42L, 42L, 42L, 42L, 42L, 42L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 32L, 32L, 32L, 32L, 32L, 32L, 32L, 32L, 32L,
32L, 32L, 32L, 32L, 32L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L,
17L, 17L, 17L, 17L, 17L, 17L), .Label = c("01", "02", "03", "04",
"05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15",
"16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26",
"27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37",
"38", "39", "40", "41", "42", "43"), class = "factor"), category1 = structure(c(4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 7L, 7L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L), .Label = c("Competitors Media",
"Competitors Price", "Distribution", "Natural Demand", "Other",
"Other Activities", "Own Media", "Own Price"), class = "factor"),
date = structure(c(14837, 14844, 14851, 14858, 14865, 14872,
14879, 14886, 14893, 14900, 14907, 14914, 14921, 14928, 14837,
14844, 14851, 14858, 14865, 14872, 14879, 14886, 14893, 14900,
14907, 14914, 14921, 14928, 14837, 14844, 14851, 14858, 14865,
14872, 14879, 14886, 14893, 14900, 14907, 14914, 14921, 14928,
14837, 14844, 14851, 14858, 14865, 14872, 14879, 14886, 14893,
14900, 14907, 14914, 14921, 14928, 14837, 14844, 14851, 14858,
14865, 14872, 14879, 14886, 14893, 14900, 14907, 14914, 14921,
14928, 14837, 14844, 14851, 14858, 14865, 14872, 14879, 14886,
14893, 14900, 14907, 14914, 14921, 14928, 14837, 14844, 14851,
14858, 14865, 14872, 14879, 14886, 14893, 14900, 14907, 14914,
14921, 14928, 14837, 14844, 14851, 14858, 14865, 14872, 14879,
14886, 14893, 14900, 14907, 14914, 14921, 14928, 14837, 14844,
14851, 14858, 14865, 14872, 14879, 14886, 14893, 14900, 14907,
14914, 14921, 14928, 14837, 14844, 14851, 14858, 14865, 14872,
14879, 14886, 14893, 14900, 14907, 14914, 14921, 14928, 14837,
14844, 14851, 14858, 14865, 14872, 14879, 14886, 14893, 14900,
14907, 14914, 14921, 14928, 14837, 14844, 14851, 14858, 14865,
14872, 14879, 14886, 14893, 14900, 14907, 14914, 14921, 14928,
14837, 14844, 14851, 14858, 14865, 14872, 14879, 14886, 14893,
14900, 14907, 14914, 14921, 14928, 14837, 14844, 14851, 14858,
14865, 14872, 14879, 14886, 14893, 14900, 14907, 14914, 14921,
14928, 14837, 14844, 14851, 14858, 14865, 14872, 14879, 14886,
14893, 14900, 14907, 14914, 14921, 14928, 14837, 14844, 14851,
14858, 14865, 14872, 14879, 14886, 14893, 14900, 14907, 14914,
14921, 14928, 14837, 14844, 14851, 14858, 14865, 14872, 14879,
14886, 14893, 14900, 14907, 14914, 14921, 14928, 14837, 14844,
14851, 14858, 14865, 14872, 14879, 14886, 14893, 14900, 14907,
14914, 14921, 14928, 14837, 14844, 14851, 14858, 14865, 14872,
14879, 14886, 14893, 14900, 14907, 14914, 14921, 14928, 14837,
14844, 14851, 14858, 14865, 14872, 14879, 14886, 14893, 14900,
14907, 14914, 14921, 14928, 14837, 14844, 14851, 14858, 14865,
14872, 14879, 14886, 14893, 14900, 14907, 14914, 14921, 14928,
14837, 14844, 14851, 14858, 14865, 14872, 14879, 14886, 14893,
14900, 14907, 14914, 14921, 14928, 14837, 14844, 14851, 14858,
14865, 14872, 14879, 14886, 14893, 14900, 14907, 14914, 14921,
14928, 14837, 14844, 14851, 14858, 14865, 14872, 14879, 14886,
14893, 14900, 14907, 14914, 14921, 14928, 14837, 14844, 14851,
14858, 14865, 14872, 14879, 14886, 14893, 14900, 14907, 14914,
14921, 14928, 14837, 14844, 14851, 14858, 14865, 14872, 14879,
14886, 14893, 14900, 14907, 14914, 14921, 14928, 14837, 14844,
14851, 14858, 14865, 14872, 14879, 14886, 14893, 14900, 14907,
14914, 14921, 14928, 14837, 14844, 14851, 14858, 14865, 14872,
14879, 14886, 14893, 14900, 14907, 14914, 14921, 14928, 14837,
14844, 14851, 14858, 14865, 14872, 14879, 14886, 14893, 14900,
14907, 14914, 14921, 14928, 14837, 14844, 14851, 14858, 14865,
14872, 14879, 14886, 14893, 14900, 14907, 14914, 14921, 14928,
14837, 14844, 14851, 14858, 14865, 14872, 14879, 14886, 14893,
14900, 14907, 14914, 14921, 14928, 14837, 14844, 14851, 14858,
14865, 14872, 14879, 14886, 14893, 14900, 14907, 14914, 14921,
14928, 14837, 14844, 14851, 14858, 14865, 14872, 14879, 14886,
14893, 14900, 14907, 14914, 14921, 14928, 14837, 14844, 14851,
14858, 14865, 14872, 14879, 14886, 14893, 14900, 14907, 14914,
14921, 14928, 14837, 14844, 14851, 14858, 14865, 14872, 14879,
14886, 14893, 14900, 14907, 14914, 14921, 14928, 14837, 14844,
14851, 14858, 14865, 14872, 14879, 14886, 14893, 14900, 14907,
14914, 14921, 14928, 14837, 14844, 14851, 14858, 14865, 14872,
14879, 14886, 14893, 14900, 14907, 14914, 14921, 14928, 14837,
14844, 14851, 14858, 14865, 14872, 14879, 14886, 14893, 14900,
14907, 14914, 14921, 14928, 14837, 14844, 14851, 14858, 14865,
14872, 14879, 14886, 14893, 14900, 14907, 14914, 14921, 14928,
14837, 14844, 14851, 14858, 14865, 14872, 14879, 14886, 14893,
14900, 14907, 14914, 14921, 14928, 14837, 14844, 14851, 14858,
14865, 14872, 14879, 14886, 14893, 14900, 14907, 14914, 14921,
14928, 14837, 14844, 14851, 14858, 14865, 14872, 14879, 14886,
14893, 14900, 14907, 14914, 14921, 14928, 14837, 14844, 14851,
14858, 14865, 14872, 14879, 14886, 14893, 14900, 14907, 14914,
14921, 14928), class = "Date"), value = c(131970.980379196,
131970.980379196, 131970.980379196, 131970.980379196, 131970.980379196,
131970.980379196, 131970.980379196, 131970.980379196, 131970.980379196,
131970.980379196, 131970.980379196, 131970.980379196, 131970.980379196,
131970.980379196, 245.776975596695, 2592.81123218455, 2394.41788371713,
794.168946135254, 777.493482699343, 1491.18842894969, 227.165967297687,
-405.943313017955, -780.434022010586, 347.653635025463, 1302.51002681435,
1418.82882868315, 391.352282511533, 139.954782408537, 557.386280511255,
860.910966958813, 1258.2157060297, 2149.37830286701, 2691.89086535467,
3293.89829993671, 4088.50777807848, 4473.20767136667, 4551.86190905075,
3741.37032522276, 4127.33070308922, 4066.07115258527, 3701.28691563376,
4325.47887879336, -72926.7301943435, -67916.3854465138, -61120.2053393434,
-54147.8698229716, -49236.4024008508, -47470.8073910042,
-41359.7595381763, -33591.8781577481, -26172.7923548125,
-21847.8659440037, -20266.7835336002, -24151.7541214564,
-26878.4009768588, -26384.0179243477, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 5064.04904072815, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -255.92797274953,
-477.999244209079, -988.82164999467, -587.738357700427, -569.535553280643,
-593.682130572193, -792.934610635432, -361.628557396076,
-255.107761517844, -302.558636405627, -461.550882648102,
-278.67688067767, -193.198364873309, -306.225679445943, 1.35968370536031e-33,
4.52442411489047e-34, 1.51049784252333e-34, 5.04284771138834e-35,
1.68016374683172e-35, 5.60840072574964e-36, 1.86632494739232e-36,
6.2210831579744e-37, 2.07369438599147e-37, 6.90445971699431e-38,
2.30462853352233e-38, 7.68209511174111e-39, 2.56855327355761e-39,
8.53042463328307e-40, 7.7469498657489e-32, 2.59145756571069e-32,
8.63819188570231e-33, 2.8793972952341e-33, 9.59799098411368e-34,
3.1947598561407e-34, 1.0626347160983e-34, 3.55125666412206e-35,
1.18603745732262e-35, 3.9488877191782e-36, 1.31629590639273e-36,
4.38765302130911e-37, 1.46026577115444e-37, 4.87440827836059e-38,
1.84217877694519e-34, 6.12949177139086e-35, 2.04871599967684e-35,
6.82905333225613e-36, 2.27524069557607e-36, 7.59523980367998e-37,
2.52841535569873e-37, 8.42805118566244e-38, 2.80823998004484e-38,
9.36079993348279e-39, 3.12137705967024e-39, 1.0393486047141e-39,
3.46449534904701e-40, 1.15594219819165e-40, 4.2168087269196e-18,
1.4056029089732e-18, 4.69872972428184e-19, 1.56222723311593e-19,
5.2208108047576e-20, 1.73491559050407e-20, 5.78305196834689e-21,
1.92768398944896e-21, 6.42561329816321e-22, 2.14053242995062e-22,
7.14849479420657e-23, 2.37747692032039e-23, 7.91153637336345e-24,
2.64253346886962e-24, 2.6723934953876e-16, 8.90797831795868e-17,
2.97046815448853e-17, 9.90156051496176e-18, 3.29937812315162e-18,
1.09979270771721e-18, 3.66597569239069e-19, 1.22313394596586e-19,
4.07711315321955e-20, 1.35675362073524e-20, 4.52251206911748e-21,
1.50750402303916e-21, 5.03643389515356e-22, 1.67538515287761e-22,
3.27912196737765e-14, 1.09609811217239e-14, 3.64601673295837e-15,
1.217632003271e-15, 4.05877334423667e-16, 1.35292444807889e-16,
4.51739180121257e-17, 1.50197544659606e-17, 4.99894118103726e-18,
1.66937118339226e-18, 5.57221425225713e-19, 1.8551116584675e-19,
6.19134916917459e-20, 2.06148996410665e-20, 1.53199757115918e-12,
5.1242677380152e-13, 1.70368695413392e-13, 5.69216338939317e-14,
1.90179008833554e-14, 6.32609341883835e-15, 2.1131000981506e-15,
7.02605782635073e-16, 2.3376169835791e-16, 7.80526348754377e-17,
2.60175449584792e-17, 8.67691727803089e-18, 2.89230575934363e-18,
9.6410191978121e-19, -1.28743119870541e-10, -4.29614801763385e-11,
-1.42733865059546e-11, -4.77663825644817e-12, -1.59692344076522e-12,
-5.29952469280492e-13, -1.76650823093497e-13, -5.89307145839907e-14,
-1.96435715279969e-14, -6.54314648738314e-15, -2.17633814051189e-15,
-7.26388184560461e-16, -2.41658325991904e-16, -8.08354166475843e-17,
-3.34213514223801e-08, -1.11404504741267e-08, -3.70998020506295e-09,
-1.24016335466693e-09, -4.11986470363931e-10, -1.37679152085905e-10,
-4.58229849690495e-11, -1.52392954598903e-11, -5.086771725922e-12,
-1.69208728899472e-12, -5.65430410856619e-13, -1.88126474987611e-13,
-6.27438578589966e-14, -2.09146192863322e-14, -7.04099686149996e-06,
-2.34277773269333e-06, -7.82614399353772e-07, -2.60871466451257e-07,
-8.69993676951523e-08, -2.89997892317174e-08, -9.66237518943249e-09,
-3.21657050867084e-09, -1.07387865801294e-09, -3.5838167478498e-10,
-1.1929170941606e-10, -3.97639031386868e-11, -1.32968465909621e-11,
-4.41961853356742e-12, 0, 0, 0, 21056.5154533907, 45784.8132599718,
50320.4307246759, 50742.4797713472, 25517.5567691784, 8505.85331241304,
2835.28380385887, 945.094601286291, 315.03163936412, 105.010440852683,
35.0035858862512, 0, 0, 0, 0, 0, 0, 0, 15708.2811797428,
26686.6324957569, 31409.9539344699, 16173.182964296, 5391.06159829487,
1797.02041072571, 599.006864594859, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, -466.722375503667, -748.416068527254, -835.761859698124,
-425.432082316856, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-1730.65348279217, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, -341.18116282158, -647.517905189578, -859.484767096219,
-1060.73176963269, -1500.8468231943, -1795.33256947583, -1994.41440518138,
-1739.85011400715, -1547.96392182655, -1981.44779169851,
-2428.93851289593, -2448.42723141998, -2953.16739350923,
-2615.75033087765, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, -18995.1206758564, -19050.3390499142, -19105.5574239719,
-19160.7757980296, -19215.9941720873, -19271.212546145, -19326.4309202028,
-19381.6492942605, -19436.8676683182, -19492.0860423759,
-19547.3044164336, -19602.5227904914, -19657.7411645491,
-19712.9595386068, 0, 0, 0, 37477.6785424152, 0, 0, 37477.6785424152,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 87201.9883875033, 87201.9883875033,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 8778.48174704963, 9116.82968716215, 9376.69728279068,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1232.01997926616,
749.716431256503, 855.612469495759, 683.200271101868, 413.768553343536,
297.785401408763, 406.027250728115, 335.445942409424, 275.653348241478,
258.757205909497, 253.982642121649, 111.617750036553, 172.55665296121,
229.624526424838, 0, -2770.21288354106, 0, 0, 0, -9640.3408347229,
0, 0, 0, -3989.10655229913, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, -6302.20972829056, -5711.37756626332, 0, 4135.49444251719,
6581.64623145537, 9567.25125213671, 10486.6421015327, 10539.4401857756,
10550.4577571942, 10640.8567346416, 11475.3377880798, 10845.1091778729,
11174.5620091962, 10224.6513107176, 10259.962431072, 10866.5875608733,
10049.5385795087, 712.161194316933, 988.507925490494, 1660.40280812631,
790.227581397336, -608.750293957247, -847.199777301192, -467.832778937881,
54.95878314737, -284.171055263922, 151.71920237511, -113.468246899084,
-308.192080042078, -94.844178901586, 249.387212102154, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)), class = "data.frame", row.names = c(NA,
-602L))
我想制作堆叠的geom_area图,但是以下内容使该图在几个地方的图层之间具有小的空白。
df %>%
group_by(date, category1) %>%
summarise(value = sum(value, na.rm = TRUE)) %>%
ggplot(aes(date, value, fill = category1)) + geom_area(position = 'stack')
我尝试使用tidyr::complete
来确保没有category1
和date
的组合丢失(因此没有值的丢失),但是df %>% complete(category1, date, fill = list(value = 0)) %>% count()
返回相同的数字作为原始的df
。
这些空白的原因是什么?我该如何处理?
答案 0 :(得分:3)
要使区域相互重叠,请尝试:
df %>%
group_by(date, category1) %>%
summarise(value = sum(value, na.rm = TRUE)) %>%
ggplot(aes(date, value, fill = category1)) +
geom_area(position = 'dodge')
将position参数从stack
更改为dodge
。
在寻找“堆积”图时,您可能必须摆脱负值或切换到条形图。请参阅以下代码,并取消注释各行:
df %>%
group_by(date, category1) %>%
summarise(value = sum(value, na.rm = TRUE)) %>%
# mutate(value=value+abs(min(value))) %>% # raise scale to min 0
ggplot(aes(date, value, fill = category1)) +
geom_area(position = 'stack') #+
# geom_bar(position="stack", stat="identity") #+
# geom_bar(position="stack", stat="identity", width=7)
当ggplot尝试将面积减小到负值然后又增大到正值时,就会出现面积图问题。不幸的是,这会使您的情节变形。因此,我想您要么必须消除负值,要么切换到小节图。
这是对代码进行的修改: