R语言 使用自定义矩阵从glht对象创建具有重要性字母的箱线图

y4ekin9u  于 2024-01-03  发布在  其他
关注(0)|答案(1)|浏览(88)

我尝试使用mgcv为HGAM制作一个具有重要性字母的箱形图。以下是我的数据:

diversitydata <- structure(list(Transect = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 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, 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, 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, 5L, 5L, 5L, 5L, 
4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 3L, 3L, 3L, 3L, 3L, 3L), 
    TimeofDay = c("15:32", "15:32", "15:32", "15:32", "15:32", 
    "10:51", "10:51", "10:51", "10:51", "10:51", "14:49", "14:49", 
    "14:49", "14:49", "8:38", "8:38", "8:38", "8:38", "16:00", 
    "16:00", "16:00", "16:00", "7:46", "7:46", "7:46", "7:46", 
    "7:46", "12:20", "12:20", "12:20", "12:20", "12:20", "12:20", 
    "12:20", "9:41", "9:41", "9:41", "9:41", "9:41", "9:41", 
    "9:41", "12:10", "12:10", "12:10", "12:10", "12:10", "8:19", 
    "8:19", "8:19", "8:19", "14:35", "14:35", "14:35", "14:35", 
    "14:35", "14:35", "14:35", "9:55", "9:55", "9:55", "9:55", 
    "9:55", "9:55", "14:08", "14:08", "14:08", "14:08", "8:18", 
    "8:18", "8:18", "8:18", "15:19", "15:19", "8:18", "8:18", 
    "8:18", "8:18", "8:18", "8:18", "11:39", "11:39", "11:39", 
    "11:39", "11:39", "11:39", "9:00", "9:00", "9:00", "9:00", 
    "9:00", "9:00", "11:53", "11:53", "11:53", "11:53", "11:53", 
    "7:38", "7:38", "7:38", "7:38", "7:38", "7:38", "15:03", 
    "15:03", "15:03", "10:20", "10:20", "10:20", "10:20", "14:29", 
    "14:29", "14:29", "14:29", "9:14", "9:14", "9:14", "9:14", 
    "9:14", "15:42", "15:42", "15:42", "15:42", "15:42", "15:42", 
    "8:45", "8:45", "8:45", "8:45", "8:45", "11:56", "11:56", 
    "11:56", "11:56", "11:56", "9:25", "9:25", "9:25", "9:25", 
    "9:25", "9:25", "9:25", "9:25", "9:25", "9:25", "12:33", 
    "12:33", "12:33", "12:23", "12:33", "8:01", "8:01", "8:01", 
    "8:01", "8:01", "15:59", "15:59", "15:59", "11:17", "11:17", 
    "11:17", "11:17", "15:16", "15:16", "15:16", "15:16", "15:16", 
    "9:03", "9:03", "9:03", "16:26", "16:26", "16:26", "16:26", 
    "8:12", "8:12", "8:12", "12:14", "12:14", "12:14", "12:14", 
    "9:59", "9:59", "9:59", "9:59", "12:26", "12:26", "12:26", 
    "12:26", "8:41", "8:41", "8:41", "8:41", "8:41", "14:58", 
    "14:58", "14:58", "14:58", "10:15", "10:15", "10:15", "10:15", 
    "14:25", "14:25", "14:25", "14:25", "9:09", "9:09", "9:09", 
    "9:09", "15:38", "15:38", "15:38", "15:38", "15:38", "15:38", 
    "8:40", "8:40", "8:40", "8:40", "8:40", "11:51", "11:51", 
    "11:51", "11:51", "11:51", "9:13", "9:13", "9:13", "9:13", 
    "9:13", "12:49", "12:49", "12:49", "12:49", "7:56", "7:56", 
    "7:56", "7:56", "15:20", "15:20", "15:20", "15:20", "10:35", 
    "10:35", "10:35", "10:35", "10:35", "14:41", "9:27", "9:27", 
    "9:27", "15:53", "15:53", "8:58", "8:58", "8:58", "8:58", 
    "12:04", "12:04", "12:04", "12:04", "9:19", "9:19", "9:19", 
    "12:41", "12:41", "12:41", "8:13", "8:13", "8:13", "16:13", 
    "16:13", "11:32", "11:32", "11:32", "15:42", "15:42", "15:42", 
    "9:52", "9:52", "9:52", "9:52", "16:46", "16:46", "16:46", 
    "9:20", "9:20", "9:20", "13:09", "13:09", "13:09", "10:42", 
    "10:42", "13:32", "13:32", "8:58", "8:58", "8:58", "8:58", 
    "16:18", "16:18", "16:18", "11:37", "11:37", "15:39", "15:39", 
    "9:48", "16:50", "16:50", "16:50", "9:24", "9:24", "9:24", 
    "13:16", "13:16", "13:16", "10:48", "10:48", "10:48", "13:37", 
    "13:37", "13:37", "13:37", "9:02", "9:02", "9:02", "9:02", 
    "16:24", "16:24", "16:24", "16:24", "11:41", "11:41", "11:41", 
    "11:41", "11:41", "11:41", "15:34", "15:34", "9:44", "9:44", 
    "9:44", "16:55", "16:55", "16:55", "9:29", "9:29", "9:29", 
    "9:29", "9:29", "13:21", "13:21", "13:21", "13:21", "10:53", 
    "10:53", "10:53", "10:53", "10:53", "13:43", "13:43", "13:43", 
    "9:07", "9:07", "9:07"), BottomTemp = c(13L, 13L, 13L, 13L, 
    13L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 
    12L, 12L, 13L, 13L, 13L, 13L, 12L, 12L, 12L, 12L, 12L, 15L, 
    15L, 15L, 15L, 15L, 15L, 15L, 16L, 16L, 16L, 16L, 16L, 16L, 
    16L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 
    13L, 13L, 13L, 13L, 13L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 
    12L, 12L, 12L, 12L, 12L, 12L, 12L, 13L, 13L, 12L, 12L, 12L, 
    12L, 12L, 12L, 15L, 15L, 15L, 15L, 15L, 15L, 16L, 16L, 16L, 
    16L, 16L, 16L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 
    13L, 13L, 13L, 13L, 13L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 
    12L, 12L, 12L, 12L, 12L, 12L, 13L, 13L, 13L, 13L, 13L, 13L, 
    12L, 12L, 12L, 12L, 12L, 15L, 15L, 15L, 15L, 15L, 16L, 16L, 
    16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 13L, 13L, 13L, 13L, 
    13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 12L, 12L, 12L, 
    12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 13L, 13L, 13L, 
    13L, 12L, 12L, 12L, 15L, 15L, 15L, 15L, 16L, 16L, 16L, 16L, 
    13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 
    13L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 
    12L, 13L, 13L, 13L, 13L, 13L, 13L, 12L, 12L, 12L, 12L, 12L, 
    15L, 15L, 15L, 15L, 15L, 16L, 16L, 16L, 16L, 16L, 13L, 13L, 
    13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 12L, 12L, 
    12L, 12L, 12L, 12L, 12L, 12L, 12L, 13L, 13L, 12L, 12L, 12L, 
    12L, 15L, 15L, 15L, 15L, 16L, 16L, 16L, 13L, 13L, 13L, 13L, 
    13L, 13L, 13L, 13L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 
    12L, 12L, 13L, 13L, 13L, 12L, 12L, 12L, 15L, 15L, 15L, 16L, 
    16L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 12L, 12L, 
    12L, 12L, 12L, 13L, 13L, 13L, 12L, 12L, 12L, 15L, 15L, 15L, 
    16L, 16L, 16L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 
    13L, 13L, 13L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 
    12L, 12L, 13L, 13L, 13L, 12L, 12L, 12L, 12L, 12L, 15L, 15L, 
    15L, 15L, 16L, 16L, 16L, 16L, 16L, 13L, 13L, 13L, 13L, 13L, 
    13L), Species = c("DOL", "RCRAB", "FLOU", "STAR", "CUNN", 
    "CUNN", "DOL", "STAR", "RCRAB", "FLOU", "STAR", "RCRAB", 
    "DOL", "CUNN", "CUNN", "STAR", "RCRAB", "DOL", "URCH", "DOL", 
    "STAR", "CUNN", "DOL", "CUNN", "STAR", "URCH", "RCRAB", "LUMP", 
    "CUNN", "FLOU", "URCH", "DOL", "RCRAB", "STAR", "DOL", "STAR", 
    "CUNN", "SCUL", "FLOU", "RCRAB", "URCH", "FLOU", "STAR", 
    "CUNN", "DOL", "RCRAB", "CUNN", "FLOU", "DOL", "STAR", "RCRAB", 
    "DOL", "CUNN", "STAR", "URCH", "PRIA", "FLOU", "DOL", "STAR", 
    "URCH", "CUNN", "FLOU", "RCRAB", "CUNN", "URCH", "DOL", "STAR", 
    "DOL", "CUNN", "STAR", "URCH", "DOL", "STAR", "CUNN", "DOL", 
    "FLOU", "URCH", "RCRAB", "STAR", "CUNN", "FLOU", "URCH", 
    "RCRAB", "STAR", "DOL", "CUNN", "FLOU", "DOL", "RCRAB", "URCH", 
    "STAR", "CUNN", "SRAV", "RCRAB", "STAR", "DOL", "URCH", "SRAV", 
    "RCRAB", "DOL", "STAR", "CUNN", "DOL", "STAR", "CUNN", "CUNN", 
    "DOL", "STAR", "ACOD", "DOL", "STAR", "CUNN", "RCRAB", "URCH", 
    "ACOD", "DOL", "STAR", "CUNN", "DOL", "URCH", "ACOD", "RCRAB", 
    "STAR", "CUNN", "RCRAB", "URCH", "CUNN", "DOL", "STAR", "DOL", 
    "RCRAB", "STAR", "URCH", "CUNN", "CUNN", "RCRAB", "URCH", 
    "FLOU", "DOL", "LOB", "STAR", "POUT", "SCUL", "ACOD", "DOL", 
    "STAR", "CUNN", "SKATE", "RCRAB", "DOL", "STAR", "LOB", "CUNN", 
    "FLOU", "CUNN", "FLOU", "DOL", "DOL", "CUNN", "FLOU", "STAR", 
    "RCRAB", "DOL", "STAR", "CUNN", "FLOU", "DOL", "CUNN", "STAR", 
    "FLOU", "CUNN", "DOL", "STAR", "DOL", "STAR", "CUNN", "DOL", 
    "CUNN", "FLOU", "STAR", "STAR", "ACOD", "DOL", "CUNN", "STAR", 
    "DOL", "RCRAB", "CUNN", "STAR", "DOL", "LUMP", "RCRAB", "CUNN", 
    "CUNN", "DOL", "RCRAB", "STAR", "STAR", "DOL", "RCRAB", "FLOU", 
    "DOL", "STAR", "RCRAB", "CUNN", "STAR", "RCRAB", "DOL", "CUNN", 
    "ACOD", "STAR", "FLOU", "CUNN", "DOL", "RCRAB", "DOL", "CUNN", 
    "ACOD", "RCRAB", "STAR", "LUMP", "FLOU", "CUNN", "DOL", "LOB", 
    "DOL", "FLOU", "CUNN", "RCRAB", "STAR", "STAR", "DOL", "RCRAB", 
    "CUNN", "DOL", "RCRAB", "ACOD", "CUNN", "CUNN", "STAR", "RCRAB", 
    "DOL", "CUNN", "PRIA", "STAR", "RCRAB", "DOL", "DOL", "RCRAB", 
    "CUNN", "DOL", "CUNN", "DOL", "DOL", "STAR", "CUNN", "RCRAB", 
    "CUNN", "DOL", "RCRAB", "FLOU", "DOL", "LOB", "CUNN", "DOL", 
    "CUNN", "RCRAB", "DOL", "RCRAB", "CUNN", "DOL", "RCRAB", 
    "DOL", "STAR", "RCRAB", "CUNN", "ACOD", "DOL", "DOL", "STAR", 
    "RCRAB", "CUNN", "RCRAB", "DOL", "CUNN", "CUNN", "DOL", "STAR", 
    "DOL", "CUNN", "RCRAB", "CUNN", "DOL", "DOL", "RCRAB", "DOL", 
    "CUNN", "RCRAB", "STAR", "CUNN", "RCRAB", "DOL", "DOL", "CUNN", 
    "CUNN", "DOL", "DOL", "DOL", "STAR", "RCRAB", "DOL", "STAR", 
    "RCRAB", "DOL", "RCRAB", "CUNN", "CUNN", "DOL", "RCRAB", 
    "RCRAB", "LUMP", "CUNN", "DOL", "DOL", "RCRAB", "LOB", "STAR", 
    "STAR", "CUNN", "DOL", "RCRAB", "SCUL", "FLOU", "DOL", "STAR", 
    "RCRAB", "CUNN", "DOL", "STAR", "STAR", "DOL", "RCRAB", "DOL", 
    "RCRAB", "STAR", "URCH", "LOB", "STAR", "FLOU", "DOL", "DOL", 
    "CUNN", "STAR", "URCH", "CUNN", "DOL", "SCUL", "STAR", "LOB", 
    "STAR", "DOL", "RCRAB", "DOL", "STAR", "URCH"), TotalLiveCover = c(30L, 
    30L, 30L, 30L, 30L, 35L, 35L, 35L, 35L, 35L, 45L, 45L, 45L, 
    45L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 
    40L, 40L, 55L, 55L, 55L, 55L, 55L, 55L, 55L, 55L, 55L, 55L, 
    55L, 55L, 55L, 55L, 50L, 50L, 50L, 50L, 50L, 45L, 45L, 45L, 
    45L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 15L, 15L, 15L, 15L, 
    15L, 15L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 
    20L, 20L, 20L, 20L, 20L, 20L, 45L, 45L, 45L, 45L, 45L, 45L, 
    35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 30L, 
    30L, 30L, 30L, 30L, 30L, 15L, 15L, 15L, 10L, 10L, 10L, 10L, 
    15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 
    15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 30L, 30L, 30L, 30L, 
    30L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 20L, 
    20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 
    15L, 15L, 15L, 15L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 
    25L, 25L, 25L, 25L, 20L, 20L, 20L, 40L, 40L, 40L, 40L, 40L, 
    40L, 40L, 40L, 35L, 35L, 35L, 35L, 20L, 20L, 20L, 20L, 20L, 
    10L, 10L, 10L, 10L, 15L, 15L, 15L, 15L, 10L, 10L, 10L, 10L, 
    10L, 10L, 10L, 10L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 
    20L, 20L, 20L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 
    25L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 10L, 10L, 10L, 
    10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 
    15L, 15L, 15L, 15L, 30L, 30L, 30L, 30L, 25L, 25L, 25L, 15L, 
    15L, 15L, 20L, 20L, 20L, 10L, 10L, 10L, 10L, 10L, 5L, 5L, 
    5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 15L, 15L, 15L, 
    10L, 10L, 5L, 5L, 5L, 5L, 5L, 5L, 10L, 10L, 10L, 5L, 5L, 
    10L, 10L, 0L, 10L, 10L, 10L, 5L, 5L, 5L, 15L, 15L, 15L, 15L, 
    15L, 15L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 25L, 25L, 
    25L, 25L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 25L, 25L, 
    25L, 25L, 25L, 25L, 30L, 30L, 30L, 30L, 30L, 55L, 55L, 55L, 
    55L, 45L, 45L, 45L, 45L, 45L, 35L, 35L, 35L, 35L, 35L, 35L
    ), Treatment = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
    2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
    2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
    2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
    2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
    2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
    2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
    2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
    2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
    2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
    2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 
    3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
    3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
    3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
    3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
    3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
    3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
    3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
    3L, 3L, 3L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), levels = c("Control Site", 
    "Reef", "Reef Adjacent"), class = "factor"), DayofYear = c(291, 
    291, 291, 291, 291, 292, 292, 292, 292, 292, 298, 298, 298, 
    298, 299, 299, 299, 299, 277, 277, 277, 277, 278, 278, 278, 
    278, 278, 234, 234, 234, 234, 234, 234, 234, 235, 235, 235, 
    235, 235, 235, 235, 263, 263, 263, 263, 263, 264, 264, 264, 
    264, 291, 291, 291, 291, 291, 291, 291, 292, 292, 292, 292, 
    292, 292, 298, 298, 298, 298, 299, 299, 299, 299, 277, 277, 
    278, 278, 278, 278, 278, 278, 234, 234, 234, 234, 234, 234, 
    235, 235, 235, 235, 235, 235, 263, 263, 263, 263, 263, 264, 
    264, 264, 264, 264, 264, 291, 291, 291, 292, 292, 292, 292, 
    298, 298, 298, 298, 299, 299, 299, 299, 299, 277, 277, 277, 
    277, 277, 277, 278, 278, 278, 278, 278, 234, 234, 234, 234, 
    234, 235, 235, 235, 235, 235, 235, 235, 235, 235, 235, 263, 
    263, 263, 263, 263, 264, 264, 264, 264, 264, 291, 291, 291, 
    292, 292, 292, 292, 298, 298, 298, 298, 298, 299, 299, 299, 
    277, 277, 277, 277, 278, 278, 278, 234, 234, 234, 234, 235, 
    235, 235, 235, 263, 263, 263, 263, 264, 264, 264, 264, 264, 
    291, 291, 291, 291, 292, 292, 292, 292, 298, 298, 298, 298, 
    299, 299, 299, 299, 277, 277, 277, 277, 277, 277, 278, 278, 
    278, 278, 278, 234, 234, 234, 234, 234, 235, 235, 235, 235, 
    235, 263, 263, 263, 263, 264, 264, 264, 264, 291, 291, 291, 
    291, 292, 292, 292, 292, 292, 298, 299, 299, 299, 277, 277, 
    278, 278, 278, 278, 234, 234, 234, 234, 235, 235, 235, 263, 
    263, 263, 264, 264, 264, 291, 291, 292, 292, 292, 298, 298, 
    298, 299, 299, 299, 299, 277, 277, 277, 278, 278, 278, 234, 
    234, 234, 235, 235, 263, 263, 264, 264, 264, 264, 291, 291, 
    291, 292, 292, 298, 298, 299, 277, 277, 277, 278, 278, 278, 
    234, 234, 234, 235, 235, 235, 263, 263, 263, 263, 264, 264, 
    264, 264, 291, 291, 291, 291, 292, 292, 292, 292, 292, 292, 
    298, 298, 299, 299, 299, 277, 277, 277, 278, 278, 278, 278, 
    278, 234, 234, 234, 234, 235, 235, 235, 235, 235, 263, 263, 
    263, 264, 264, 264)), row.names = c(1L, 2L, 3L, 4L, 5L, 6L, 
7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 
20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 38L, 39L, 40L, 41L, 42L, 
43L, 44L, 45L, 46L, 47L, 48L, 49L, 50L, 51L, 52L, 53L, 54L, 55L, 
56L, 57L, 58L, 59L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 68L, 
69L, 70L, 71L, 72L, 73L, 74L, 75L, 76L, 77L, 78L, 79L, 80L, 81L, 
82L, 83L, 84L, 85L, 86L, 87L, 88L, 89L, 99L, 100L, 101L, 102L, 
103L, 104L, 105L, 106L, 107L, 108L, 109L, 110L, 111L, 112L, 113L, 
114L, 115L, 116L, 117L, 118L, 119L, 120L, 121L, 122L, 123L, 124L, 
125L, 126L, 127L, 128L, 129L, 130L, 131L, 132L, 133L, 134L, 135L, 
136L, 137L, 138L, 139L, 140L, 141L, 142L, 143L, 144L, 145L, 146L, 
147L, 148L, 158L, 159L, 160L, 161L, 162L, 163L, 164L, 165L, 166L, 
167L, 168L, 169L, 170L, 171L, 172L, 173L, 174L, 175L, 176L, 177L, 
178L, 179L, 180L, 181L, 182L, 183L, 184L, 185L, 186L, 187L, 188L, 
189L, 190L, 191L, 192L, 193L, 194L, 195L, 196L, 197L, 198L, 199L, 
200L, 201L, 202L, 203L, 204L, 215L, 216L, 217L, 218L, 219L, 220L, 
221L, 222L, 223L, 224L, 225L, 226L, 227L, 228L, 229L, 230L, 231L, 
232L, 233L, 234L, 235L, 236L, 237L, 238L, 239L, 240L, 241L, 242L, 
243L, 244L, 245L, 246L, 247L, 248L, 249L, 250L, 251L, 252L, 253L, 
254L, 255L, 256L, 257L, 258L, 266L, 267L, 268L, 269L, 270L, 271L, 
272L, 273L, 274L, 275L, 276L, 277L, 278L, 279L, 280L, 281L, 282L, 
283L, 284L, 285L, 286L, 287L, 288L, 289L, 290L, 291L, 292L, 293L, 
294L, 295L, 296L, 297L, 298L, 299L, 300L, 301L, 302L, 309L, 310L, 
311L, 312L, 313L, 314L, 315L, 316L, 317L, 318L, 319L, 320L, 321L, 
322L, 323L, 324L, 325L, 326L, 327L, 328L, 329L, 330L, 331L, 332L, 
333L, 334L, 335L, 336L, 337L, 338L, 339L, 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, 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, 425L, 426L, 427L, 428L, 429L, 430L, 431L, 432L, 
433L, 434L, 435L, 436L, 437L, 438L, 439L), class = "data.frame")

字符串
这是我的模型:

library(mgcv)
gam3 <- gam(Diversity ~ Treatment +
              s(DayofYear, Transect, k=3, bs="fs") +
             s(TotalLiveCover, k=4), 
           data=diversitydata,
         family = gaussian(link=identity),
         method="REML")


multcomp不适用于mgcv的开箱即用-你必须创建自己的矩阵,我这样做了,然后使用glht完成一个单步比较:

library(multcomp)

#Set up matrix
contr <- matrix(0, nrow = 3, ncol = length(coef(gam3)))
colnames(contr) <- names(coef(gam3))
rownames(contr) <- c("reef - cont", "adj - cont", "adj - reef")
contr[, 2:3] <- rbind(c(1, 0), c(0, 1), c(-1, 1))
contr[, 1:5]

comp <- glht(gam3, linfct = contr)
summary(comp)


当我尝试使用cld比较来提取重要性字母时,我得到了关于长度的错误,我假设这是因为我创建了自己的矩阵。有人知道一种方法可以从我的矩阵中提取重要性字母并将其应用于箱线图吗?

r7s23pms

r7s23pms1#

运行cld(comp)时得到的错误是
extr(object)中出错:length(object$focus)== 1不是TRUE这是因为我们没有明确地告诉glht()什么变量是我们的焦点,不像我们使用lmer对象时可以执行f.exglht(lmm, linfct=mcp(Treatment="Tukey"))。 修复很简单,我们只需手动将焦点设置为Treatment`:

comp$focus <- "Treatment"
cld(comp)
# ControlSite         Reef ReefAdjacent 
#         "a"          "b"          "a"

字符串
至于箱线图,multcomp具有用于置信区间和紧凑字母显示的绘图功能:

par(mfrow=c(1, 2), mar=c(4, 8, 3, 1), mgp=c(2.5, 0.7, 0),
  cex.axis=0.8, cex.main=0.8)
ci <- confint(comp)
rownames(ci$confint) <- gsub(" - ", "\n- ", rownames(ci$confint))
plot(ci)
plot(cld(comp))

我添加了一个换行符,这样边距就不会那么大了。

相关问题