I have this data frame:
dput(df)
structure(list(X = c(337L, 338L, 339L, 340L, 341L, 342L, 343L,
344L, 345L, 346L, 347L, 348L, 349L, 350L, 351L, 352L, 353L, 354L,
355L, 356L, 357L, 358L, 359L, 360L, 361L, 362L, 363L, 364L, 365L,
366L, 367L, 368L, 369L, 370L, 371L, 372L, 373L, 374L, 375L, 376L,
377L, 378L, 379L, 380L, 381L, 382L, 383L, 384L, 385L, 386L, 387L,
388L, 389L, 390L, 391L, 392L, 393L, 394L, 395L, 396L, 397L, 398L,
399L, 400L, 401L, 402L, 403L, 404L, 405L, 406L, 407L, 408L, 409L,
410L, 411L, 412L, 413L, 414L, 415L, 416L, 417L, 418L, 419L, 420L,
421L, 422L, 423L, 424L, 425L, 426L, 427L, 428L, 429L, 430L, 431L,
432L, 433L, 434L, 435L, 436L, 437L, 438L, 439L, 440L, 441L, 442L,
443L, 444L, 445L, 446L, 447L, 448L, 449L, 450L, 451L, 452L, 453L,
454L, 455L, 456L, 457L, 458L, 459L, 460L, 461L, 462L, 463L, 464L,
465L, 466L, 467L, 468L, 469L, 470L, 471L, 472L, 473L, 474L, 475L,
476L, 477L, 478L, 479L, 480L, 481L, 482L, 483L, 484L, 485L, 486L,
487L, 488L, 489L, 490L, 491L, 492L, 493L, 494L, 495L, 496L, 497L,
498L, 499L, 500L, 501L, 502L, 503L, 504L, 841L, 842L, 843L, 844L,
845L, 846L, 847L, 848L, 849L, 850L, 851L, 852L, 853L, 854L, 855L,
856L, 857L, 858L, 859L, 860L, 861L, 862L, 863L, 864L, 865L, 866L,
867L, 868L, 869L, 870L, 871L, 872L, 873L, 874L, 875L, 876L, 877L,
878L, 879L, 880L, 881L, 882L, 883L, 884L, 885L, 886L, 887L, 888L,
889L, 890L, 891L, 892L, 893L, 894L, 895L, 896L, 897L, 898L, 899L,
900L, 901L, 902L, 903L, 904L, 905L, 906L, 907L, 908L, 909L, 910L,
911L, 912L, 913L, 914L, 915L, 916L, 917L, 918L, 919L, 920L, 921L,
922L, 923L, 924L, 925L, 926L, 927L, 928L, 929L, 930L, 931L, 932L,
933L, 934L, 935L, 936L, 937L, 938L, 939L, 940L, 941L, 942L, 943L,
944L, 945L, 946L, 947L, 948L, 949L, 950L, 951L, 952L, 953L, 954L,
955L, 956L, 957L, 958L, 959L, 960L, 961L, 962L, 963L, 964L, 965L,
966L, 967L, 968L, 969L, 970L, 971L, 972L, 973L, 974L, 975L, 976L,
977L, 978L, 979L, 980L, 981L, 982L, 983L, 984L, 985L, 986L, 987L,
988L, 989L, 990L, 991L, 992L, 993L, 994L, 995L, 996L, 997L, 998L,
999L, 1000L, 1001L, 1002L, 1003L, 1004L, 1005L, 1006L, 1007L,
1008L, 1345L, 1346L, 1347L, 1348L, 1349L, 1350L, 1351L, 1352L,
1353L, 1354L, 1355L, 1356L, 1357L, 1358L, 1359L, 1360L, 1361L,
1362L, 1363L, 1364L, 1365L, 1366L, 1367L, 1368L, 1369L, 1370L,
1371L, 1372L, 1373L, 1374L, 1375L, 1376L, 1377L, 1378L, 1379L,
1380L, 1381L, 1382L, 1383L, 1384L, 1385L, 1386L, 1387L, 1388L,
1389L, 1390L, 1391L, 1392L, 1393L, 1394L, 1395L, 1396L, 1397L,
1398L, 1399L, 1400L, 1401L, 1402L, 1403L, 1404L, 1405L, 1406L,
1407L, 1408L, 1409L, 1410L, 1411L, 1412L, 1413L, 1414L, 1415L,
1416L, 1417L, 1418L, 1419L, 1420L, 1421L, 1422L, 1423L, 1424L,
1425L, 1426L, 1427L, 1428L, 1429L, 1430L, 1431L, 1432L, 1433L,
1434L, 1435L, 1436L, 1437L, 1438L, 1439L, 1440L, 1441L, 1442L,
1443L, 1444L, 1445L, 1446L, 1447L, 1448L, 1449L, 1450L, 1451L,
1452L, 1453L, 1454L, 1455L, 1456L, 1457L, 1458L, 1459L, 1460L,
1461L, 1462L, 1463L, 1464L, 1465L, 1466L, 1467L, 1468L, 1469L,
1470L, 1471L, 1472L, 1473L, 1474L, 1475L, 1476L, 1477L, 1478L,
1479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L, 1L, 4L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 6L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L), .Label = c("candiano", "Lido_Spina", "Porto_Corsini",
"Punta_Marina", "Sito1", "Sito2"), class = "factor"), Campione = structure(c(40L,
39L, 38L, 155L, 37L, 36L, 153L, 50L, 51L, 156L, 34L, 152L, 73L,
154L, 75L, 76L, 157L, 41L, 42L, 43L, 44L, 45L, 35L, 47L, 48L,
49L, 6L, 7L, 13L, 21L, 162L, 164L, 166L, 2L, 8L, 46L, 14L, 165L,
167L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, 31L, 12L, 33L,
150L, 151L, 111L, 74L, 3L, 9L, 15L, 18L, 4L, 10L, 158L, 159L,
160L, 161L, 17L, 20L, 1L, 126L, 127L, 128L, 52L, 53L, 54L, 55L,
56L, 57L, 58L, 22L, 163L, 139L, 140L, 141L, 142L, 143L, 144L,
145L, 146L, 147L, 32L, 149L, 109L, 110L, 72L, 84L, 112L, 113L,
114L, 115L, 116L, 77L, 16L, 19L, 5L, 11L, 82L, 83L, 61L, 85L,
86L, 87L, 129L, 130L, 131L, 132L, 133L, 134L, 135L, 59L, 60L,
123L, 62L, 62L, 63L, 64L, 65L, 66L, 67L, 68L, 148L, 108L, 70L,
71L, 137L, 124L, 125L, 98L, 99L, 88L, 89L, 117L, 78L, 79L, 80L,
81L, 122L, 91L, 138L, 97L, 90L, 136L, 100L, 101L, 94L, 102L,
92L, 93L, 96L, 69L, 103L, 95L, 105L, 119L, 107L, 104L, 118L,
120L, 121L, 106L, 106L, 109L, 105L, 110L, 108L, 121L, 122L, 102L,
111L, 107L, 146L, 147L, 104L, 149L, 150L, 112L, 148L, 103L, 145L,
120L, 117L, 4L, 10L, 123L, 18L, 125L, 126L, 127L, 124L, 129L,
118L, 119L, 91L, 92L, 93L, 94L, 95L, 96L, 97L, 98L, 99L, 128L,
101L, 60L, 61L, 62L, 23L, 24L, 25L, 26L, 27L, 28L, 151L, 113L,
114L, 115L, 116L, 3L, 9L, 15L, 78L, 79L, 80L, 81L, 82L, 83L,
84L, 85L, 86L, 87L, 130L, 131L, 132L, 133L, 134L, 135L, 136L,
137L, 138L, 139L, 140L, 100L, 59L, 142L, 143L, 144L, 165L, 62L,
63L, 64L, 65L, 66L, 67L, 152L, 153L, 154L, 155L, 156L, 157L,
158L, 159L, 160L, 161L, 40L, 16L, 19L, 5L, 11L, 17L, 20L, 88L,
89L, 90L, 13L, 21L, 162L, 164L, 166L, 2L, 8L, 12L, 14L, 141L,
58L, 22L, 163L, 74L, 167L, 76L, 77L, 39L, 41L, 42L, 68L, 69L,
70L, 71L, 72L, 73L, 7L, 75L, 49L, 50L, 51L, 52L, 53L, 43L, 44L,
45L, 46L, 1L, 6L, 34L, 48L, 36L, 37L, 38L, 56L, 57L, 54L, 55L,
29L, 35L, 32L, 33L, 30L, 31L, 47L, 66L, 64L, 62L, 67L, 103L,
65L, 101L, 63L, 58L, 59L, 60L, 102L, 62L, 99L, 100L, 77L, 37L,
38L, 39L, 40L, 41L, 42L, 43L, 44L, 61L, 48L, 49L, 50L, 51L, 52L,
53L, 54L, 55L, 56L, 57L, 12L, 14L, 22L, 163L, 137L, 138L, 165L,
167L, 23L, 24L, 25L, 68L, 69L, 70L, 71L, 72L, 73L, 74L, 75L,
76L, 36L, 3L, 9L, 15L, 78L, 79L, 80L, 81L, 82L, 45L, 46L, 47L,
86L, 87L, 88L, 89L, 90L, 91L, 92L, 93L, 94L, 8L, 135L, 136L,
97L, 98L, 34L, 139L, 140L, 141L, 142L, 26L, 27L, 28L, 29L, 30L,
31L, 32L, 33L, 17L, 35L, 154L, 155L, 156L, 18L, 4L, 10L, 16L,
19L, 83L, 84L, 85L, 110L, 20L, 1L, 6L, 7L, 13L, 21L, 162L, 164L,
166L, 95L, 96L, 109L, 11L, 111L, 112L, 113L, 114L, 115L, 143L,
104L, 105L, 106L, 107L, 108L, 5L, 149L, 123L, 124L, 125L, 126L,
127L, 157L, 158L, 159L, 160L, 161L, 121L, 134L, 153L, 150L, 151L,
152L, 130L, 131L, 128L, 129L, 148L, 144L, 132L, 2L, 116L, 133L,
122L, 146L, 147L, 120L, 145L, 118L, 119L, 117L), .Label = c("A_1",
"A_2", "A_LS", "A_PC", "A_PM", "B_1", "B1_1", "B1_2", "B1_LS",
"B1_PC", "B1_PM", "B_2", "B2_1", "B2_2", "B2_LS", "B2_PC", "B2_PM",
"B_LS", "B_PC", "B_PM", "C_1", "C_2", "C386", "C387", "C388",
"C389", "C390", "C391", "C392", "C393", "C394", "C395", "C396",
"C397", "C398", "C399", "C400", "C401", "C402", "C403", "C404",
"C405", "C406", "C407", "C408", "C409", "C410", "C411", "C412",
"C413", "C414", "C415", "C416", "C417", "C418", "C419", "C420",
"C421", "C422", "C423", "C424", "C425", "C426", "C427", "C428",
"C429", "C430", "C431", "C432", "C433", "C434", "C435", "C436",
"C437", "C438", "C439", "C440", "C441", "C442", "C443", "C444",
"C445", "C446", "C447", "C448", "C449", "C450", "C451", "C452",
"C453", "C454", "C455", "C456", "C457", "C458", "C459", "C460",
"C461", "C462", "C463", "C464", "C465", "C466", "C467", "C468",
"C469", "C470", "C471", "C472", "C473", "C474", "C475", "C476",
"C477", "C478", "C479", "C480", "C481", "C482", "C483", "C484",
"C485", "C486", "C487", "C488", "C489", "C490", "C491", "C492",
"C493", "C494", "C495", "C496", "C497", "C498", "C499", "C500",
"C501", "C502", "C503", "C504", "C505", "C506", "C507", "C508",
"C509", "C510", "C511", "C512", "C513", "C514", "C515", "C516",
"C517", "C518", "C519", "C520", "C521", "C522", "C523", "C524",
"D_1", "D_2", "E_1", "E_2", "F_1", "F_2"), class = "factor"),
zona = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L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0.09, 0.15, 0.1, 0.1, 0.1, 0.11, 0.09, 0.12, 0.12, 0.12,
0.12, 0.16, 0.1, 0.1, 0.1, 0.1, 0.2, 0.15, 0.1, 0.14, 0.12,
0.15, 0.025, 0.16, 0.18, 0.16, 0.025, 0.15, 0.08, 0.09, 0.1,
0.15, 0.17, 0.11, 0.05, 0.05, 0.12, 0.15, 0.12, 0.025, 0.1,
0.11, 0.17, 0.16, 0.12, 0.05, 0.12, 0.12, 0.13, 0.17, 0.13,
0.14, 0.12, 0.12, 0.11, 0.12, 0.13, 0.15, 0.12, 0.12, 0.1,
0.1, 0.12, 0.1, 0.13, 0.13, 0.18, 0.1, 0.14, 0.12, 0.1, 0.1,
0.18, 0.2, 0.15, 0.1, 0.11, 0.13, 0.11, 0.24, 0.16, 0.13,
0.15, 0.15, 0.22, 0.1, 85.75, 63.25, 43.6, 84.5, 84, 95.4,
98, 35.6, 79.6, 71.6, 73.2, 84, 54, 89, 99, 94.75, 70.6,
92.25, 84.83, 78.5, 70.17, 92.5, 94.67, 93.75, 75.2, 64.75,
66, 75.6, 82.4, 80.2, 78.8, 81, 79, 75.6, 79.2, 85.9, 57,
93.9, 97.9, 96.25, 84, 53.9, 56.1, 108.5, 111.75, 104.5,
78.25, 82.75, 87.25, 86.05, 85, 96, 102.25, 100.5, 100, 77,
84.3, 83.9, 52, 90.67, 85.75, 76.67, 86.33, 93.67, 70.5,
86.6, 77.67, 86.33, 74, 73.67, 86.67, 87.5, 72, 89.67, 93,
95, 93.5, 96, 88, 91, 86, 104.5, 90, 86.5, 85, 100.25, 81.25,
93.2, 109.75, 105, 104, 87.8, 99.75, 92.67, 47, 88.2, 73,
95, 94, 98.7, 100.4, 91.5, 63, 94.2, 89.33, 90.33, 83.67,
75.6, 86.8, 99.7, 90, 88.7, 88.4, 99.8, 76.4, 57.8, 52.5,
93, 91, 108, 91.5, 105, 98, 69.5, 79.75, 68.6, 103, 81, 90,
101.2, 102.6, 96.6, 100.8, 81, 90, 65, 79, 102.67, 102, 107,
107.5, 93, 70.2, 70.2, 67, 90.33, 71.5, 61.17, 64.6, 84.8,
87.5, 96.67, 76, 101, 100.75, 97.8, 77.4, 83.4, 79, 79, 55,
59.33, 98, 95.25, 82, 87, 70, 91), LCB_pelite = c(17, 17,
17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17,
17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17,
17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17,
17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17,
17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17,
17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17,
17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17,
17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17,
17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17,
17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17,
17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17,
17, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2,
0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2,
0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2,
0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2,
0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2,
0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2,
0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2,
0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2,
0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2,
0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2,
0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2,
0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2,
0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2,
0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2,
0.2, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
50, 50, 50, 50, 50), LCB = c(25, 25, 25, 25, 25, 25, 25,
25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 0.35, 0.35, 0.35,
0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35,
0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35,
0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35,
0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35,
0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35,
0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35,
0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35,
0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35,
0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35,
0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35,
0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35,
0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35,
0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35,
0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35,
0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35,
0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35,
0.35, 0.35, 0.35, 0.35, 0.35, 100, 100, 100, 100, 100, 100,
100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
100, 100, 100, 100, 100, 100), LCL = c(32, 32, 32, 32, 32,
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
32, 32, 32, 32, 32, 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0.8, 0.8,
0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 360,
360, 360, 360, 360, 360, 360, 360, 360, 360, 360, 360, 360,
360, 360, 360, 360, 360, 360, 360, 360, 360, 360, 360, 360,
360, 360, 360, 360, 360, 360, 360, 360, 360, 360, 360, 360,
360, 360, 360, 360, 360, 360, 360, 360, 360, 360, 360, 360,
360, 360, 360, 360, 360, 360, 360, 360, 360, 360, 360, 360,
360, 360, 360, 360, 360, 360, 360, 360, 360, 360, 360, 360,
360, 360, 360, 360, 360, 360, 360, 360, 360, 360, 360, 360,
360, 360, 360, 360, 360, 360, 360, 360, 360, 360, 360, 360,
360, 360, 360, 360, 360, 360, 360, 360, 360, 360, 360, 360,
360, 360, 360, 360, 360, 360, 360, 360, 360, 360, 360, 360,
360, 360, 360, 360, 360, 360, 360, 360, 360, 360, 360, 360,
360, 360, 360, 360, 360, 360, 360, 360, 360, 360, 360, 360,
360, 360, 360, 360, 360, 360, 360, 360, 360, 360, 360, 360,
360, 360, 360, 360, 360, 360, 360, 360, 360, 360, 360)), .Names = c("X",
"variable", "Area", "Campione", "zona", "value", "LCB_pelite",
"LCB", "LCL"), class = "data.frame", row.names = c(NA, -504L))
and that's the code I used to produce the following plot (with the old data, no with these):
ggplot(df)+
stat_ecdf(aes(x=value, color=Area))+
geom_vline(aes(xintercept=LCB_pelite), size=2, color="red")
What I'd like to do is to add in the legend the reference to geom_vline
.
In other words, I'd like to have 2 legend: the first is that one automatically added by ggplot while the second one should have another title and the symbol of geom_vline
.
I also tried to do the following hack:
ggplot(df)+
stat_ecdf(aes(x=value, color=Area))+
geom_vline(aes(xintercept=LCB_pelite, color="Limit"), size=2)
with the following result:
but it has 2 problems: the first is that the color in randomly chosen by ggplot and the second problem is that the symbol is inside the old legend while I need it in a separate legend.
I hope I made myself clear..
Thanks
EDIT
I made some "hacks" to my dataframe and now it looks like (sse dput
from above).
Then I melt it:
require("reshape2")
df_melt<-(melt(df))
and I've written this piece of code:
require("ggplot2")
ggplot(df, aes(x=value, color=zona, linetype = factor(LCB_pelite)))+
stat_ecdf()+
facet_wrap(~variable, scales="free_x" ) +
geom_vline(aes(xintercept=LCB_pelite), color="red", linetype="dashed") +
# geom_vline(aes(xintercept=LCB), color="orangered", linetype="dashed") +
# geom_vline(aes(xintercept=LCL), color="blue", linetype="dashed") +
scale_linetype(name = "Limit") +
guides(linetype = guide_legend(override.aes = list(colour = "red")))
What I'd need now is:
- add the other 2
geom_vline
(commented in the code from above) in the legend - adjust the legend in order that the elements are (LCB_pelite, LCB, LCL and not 0.2, 17 and 50)
is it possible with ggplot?
Thanks!
You may add a
linetype
aesthetics to theggplot
call, and then fix the color in the legend usingguides
/override.aes
:Please note the spelling in
override.aes
: colour with u (for some reason doesn't 'color' work here...)You can have a separate legend if you map a linetype. However, the
vline
would also show up in the colour legend and I cannot find a way to supress that:So I'm almost there. I re-reshaped the data from above with this piece of code:
then I rename some variables ("value" appears twice) and I got this:
I'm able now to use
limite
ascolor
ingeom_vline
:to get this plot:
))
one last thing..
how can now separate LCB, LCB_pelite and LCL in another legend with another title?