简体   繁体   English

如何使用 plotmeans() function 在 gplots package 在 R 中使用均值和置信区间条 plot

[英]How to plot the mean, and confidence interval bars using the plotmeans() function in the gplots package in R

Problem:问题:

I am attempting to produce a plot using the function plotmeans() in the gplots package .我试图在 gplots package 中使用 function plotmeans()生成一个plot My goals are to display mean FID sightings (see the data frame's below called 'FID' and 'Mean_FID') with associated upper and lower confidence interval bars , and n labels我的目标是显示平均 FID 目击(参见下面称为“FID”和“Mean_FID”的数据框)以及相关的上下置信区间条n 个标签

Dataframe Structure Dataframe结构

  • I have a large data frame called 'FID' with 918 rows, and the main column headings are:-我有一个名为“FID”的大型数据框,有 918 行,主要列标题是:-
  1. FID = number of sightings FID = 目击次数
  2. Year = 2015-2017年份 = 2015-2017
  3. Month = January-December月 = 一月至十二月
  • I have modified the data frame called 'FID' to show the average sightings per month per year.我修改了名为“FID”的数据框,以显示每年每月的平均目击事件。 The data frame is called "Mean_FID", with 36 rows and this was used to produce figure 4 (see below).数据框称为“Mean_FID”,有 36 行,用于生成图 4(见下文)。 The main column headings are:-主要栏目标题是:-
  1. Year = number of sightings年份 = 目击次数
  2. Month = January-February月 = 一月至二月
  3. Frequency FID = Mean sightings per month per year Frequency FID = 每年每月平均目击次数

GOAL - Desire plot目标 - 欲望 plot

I would like to incorporate all the features listed below into one desired plot using the function plotmeans()我想使用 function plotmeans() 将下面列出的所有功能合并到一个所需的 plot 中

ci.label = I would like to display the actual upper and lower interval values at the end of each confidence interval bar. ci.label = 我想在每个置信区间条的末尾显示实际的上限和下限区间值。

digits = I would like all confidence interval labels to have 3 significant digits (see figure 4). digits = 我希望所有置信区间标签都具有 3 位有效数字(见图 4)。

n.label = I would like to show the number of observations in each group at the bottom of each interval bar on the x-axis in the plot space (see figure 1) n.label = 我想在 plot 空间的 x 轴上的每个区间条的底部显示每个组中的观察数(见图 1)

Dates = all months need to be displayed in chronological order between January-December on the x-axis Dates = 所有月份都需要在 x 轴上按 1 月至 12 月之间的时间顺序显示

Adjust y-axis = the y-axis limits are in figures 1 + 2 (see below) are incorrect because the values state the number of rows in the data frame called 'FID', rather than the actual mean number of sightings eg April contains 111 sightings, but the y-axis in figures 1 and 2 states there were 390 sightings, which is incorrect.调整 y 轴= 图 1 + 2 中的 y 轴限制(见下文)不正确,因为值 state 是称为“FID”的数据框中的行数,而不是实际的平均目击次数,例如四月包含111 次目击,但图 1 和图 2 中的 y 轴表示有 390 次目击,这是不正确的。 Figures 3 and 4 (see below) display the correct y-axis limits.图 3 和图 4(见下文)显示了正确的 y 轴限制。

Issues问题

I have so far produced 4 plots, where each plot displays at least 1 or 2 of the desired features listed above.到目前为止,我已经制作了 4 个图,其中每个 plot 显示至少 1 或 2 个上面列出的所需特征。 However, I cannot produce one plot containing all the desired features.但是,我无法生成包含所有所需功能的 plot。 I am feeling really confused as I have modified both my R-code and data frame in an attempt to produce the desired plot. I have tried many times and I really can't understand what I am doing wrong.我感到非常困惑,因为我修改了我的 R 代码和数据框以试图生成所需的 plot。我已经尝试了很多次,但我真的不明白我做错了什么。

If anyone can help me solve this problem, I would like to express my deepest appreciation.如果有人能帮我解决这个问题,我要表示最深切的谢意。

Thank you:)谢谢:)

Summarise Data Frame汇总数据框

#To begin with, I tried to find the correct values for 
#the mean count of observations with associated standard 
#deviation, standard error, and the upper and lower confidence 
#intervals using dplyr() based on Dan Chaltiel's suggestions (below):

library(dplyr)

##Count the number of row observations and count by "Year" and "Month"

  Summarised_FID_Count<-FID %>% 
                        dplyr::mutate(Month=ordered(Month, levels=month_levels)) %>%
                        dplyr::count(Year, Month)
     
##Summarise the data frame "FID'


Summarise_FID_Data<-Summarised_FID_Count %>%
                                  group_by(Month) %>%
                                  dplyr::summarise(mean.month = mean(n, na.rm = TRUE),
                                  sd.month = sd(n, na.rm = TRUE),
                                  n.month = n()) %>%
                                  dplyr::mutate(se.month = sd.month / sqrt(n.month),
                                  lower.ci.month = mean.month - qt(1 - (0.05 / 2), n.month - 1) * se.month,
                                  upper.ci.month = mean.month + qt(1 - (0.05 / 2), n.month - 1) * se.month)

##One problem, the output produces negative lower 
##confidence interval values which I don't think is 
##correct because you cannot have a negative number of 
##observations. 

# A tibble: 11 x 7
   Month     mean.month sd.month n.month se.month lower.ci.month upper.ci.month
   <ord>          <dbl>    <dbl>   <int>    <dbl>          <dbl>          <dbl>
 1 January         37.7     5.69       3     3.28          23.5            51.8
 2 February        31.3     4.93       3     2.85          19.1            43.6
 3 March           37       5.29       3     3.06          23.9            50.1
 4 April           37      12.3        3     7.09           6.47           67.5
 5 May             11       7.94       3     4.58          -8.72           30.7
 6 July             8       1.41       2     1             -4.71           20.7
 7 August          29.7     9.29       3     5.36           6.59           52.7
 8 September       28.7    16.4        3     9.49         -12.2            69.5
 9 October         27.3    12.5        3     7.22          -3.73           58.4
10 November        27      17.7        3    10.2          -16.9            70.9
11 December        33.7     4.04       3     2.33          23.6            43.7

R-code for figures 1, 2, 3, and 4 (see below):图 1、2、3 和 4 的 R 代码(见下文):

##Download package
library(gplots)

#Convert `month_vector` to a factor with ordered level
Month.label<- factor(FID, order = TRUE, levels =c('January', 
                                                  'February',
                                                  'March',
                                                  'April',
                                                  'May', 
                                                  'June',
                                                  'July',
                                                  'August',
                                                  'September',
                                                  'October',
                                                  'November',
                                                  'December'))

##Code for figure 1
    dev.new()
    plotmeans(FID~Month, data=FID,
              ylab="Mean Blue Whale Sightings",
              xlab="Months")
    
    ##Code for sample 2
    dev.new
    plotmeans(FID~Month, data=FID,
              ci.label = TRUE,
              xaxt = n,
              digits = 3,
              ylab="Mean Blue Whale Sightings",
              xlab="Months")
    
    axis(side = 1, at = seq(1, 12, by = 1), labels = FALSE)
    text(seq(1, 12, by=1), par("usr")[3] - 0.2, labels=unique(month.label), srt = 75, pos = 1, xpd = TRUE, cex=0.3)
    
    ##Code for sample 3:
    
    ##Filter the data frame using the function count() in dplyr
    
    New_FID<-FID %>% dplyr::select(Month, FID) %>% 
                     dplyr::count(Month) %>% as.data.frame
    
    ##Examine the structure of the filtered data frame showing the month and total whale sightings
    
    str(New_FID)
    
    ##Produce a new data frame
    
    FID_Plotmeans<-as.data.frame(New_FID)
    
    ##Rename the columns
    
    colnames(FID_Plotmeans)<-c("Month", "FID_Sightings")
    
    ##Plot the means
    
    dev.new()
    plotmeans(FID_Sightings,
              data=New_Blue_Plotmeans,
              ylab="Mean Blue Whale Sightings",
              xlab="Months")
    
    ##Code for sample 4:
    
    plotmeans(Frequency_FID~Month, data=Mean_FID,
              text.n.label = Month.label,
              ci.label = TRUE,
              digits = 3,
              ylab="Mean Blue Whale Sightings",
              xlab="Months")
    
    Warning messages:
    1: In arrows(x, li, x, pmax(y - gap, li), col = barcol, lwd = lwd,  :
      zero-length arrow is of indeterminate angle and so skipped
    2: In arrows(x, ui, x, pmin(y + gap, ui), col = barcol, lwd = lwd,  :
      zero-length arrow is of indeterminate angle and so skipped
                                                                                                                      
                                    


           
                                                         
                                                                   

Problems with Figures 1, 2, 3, and 4 (see below):图 1、2、3 和 4 的问题(见下文):

Figure 1 (see below):图 1(见下图):

  1. Incorrect y-axis limits - the plot shows the mean number of rows in the data frame rather than the mean number of FID sightings (eg there are 111 sightings in April, but the y-axis limits state the mean number of sightings is 390, which is not correct.不正确的 y 轴限制 - plot 显示数据框中的平均行数而不是 FID 目击事件的平均数(例如,4 月份有 111 次目击事件,但 y 轴限制 state 平均目击事件数为 390,这是不正确的。
  2. The months on the x-axis are not in chronological order - January-December x 轴上的月份未按时间顺序排列 - 1 月至 12 月
  3. Good news because the n.labels are displayed on the x-axis.好消息,因为n.labels显示在 x 轴上。

Figure 2 (see below):图 2(见下图):

  1. Incorrect y-axis limits - the plot shows the mean number of rows in the data frame rather than the mean number of FID sightings (eg there are 111 sightings in April, but the y-axis limits state the mean number of sightings is 390, which is not possible.不正确的 y 轴限制 - plot 显示数据框中的平均行数而不是 FID 目击事件的平均数(例如,4 月份有 111 次目击事件,但 y 轴限制 state 平均目击事件数为 390,这是不可能的。
  2. The months on the x-axis are not in chronological order - January-December x 轴上的月份未按时间顺序排列 - 1 月至 12 月
  3. The adjoining line to connect each mean sighting per month is missing缺少连接每个月平均目击事件的相邻线
  4. The ci.labels are missing ci.labels 丢失
  5. The n.labels are missing n.labels 丢失

Figure 3 (see below):图 3(见下图):

  1. The months on the x-axis are not in chronological order - January-December x 轴上的月份未按时间顺序排列 - 1 月至 12 月
  2. The n.labels are displayed as n=1 for each grouping, which is incorrect每个分组的 n.labels 显示为 n=1,这是不正确的
  3. The confidence interval bars are missing置信区间条丢失
  4. The ci.labels are missing ci.labels 丢失
  5. Good news because the y-axis limits are correct.好消息,因为 y 轴限制是正确的。

Sample 4 (see below):示例 4(见下文):

  1. The months on the x-axis are not in chronological order - January-December x 轴上的月份未按时间顺序排列 - 1 月至 12 月
  2. The n.labels are displayed as n=3 for each grouping, which is incorrect每个分组的 n.labels 显示为 n=3,这是不正确的
  3. Good news, the ci.labels stating the upper and lower confidence intervals are displayed on the plot好消息,说明上下置信区间的 ci.labels 显示在 plot
  4. One of the ci.labels overlaps the n.label for the month of November, so the values are ineligible其中一个 ci.labels 与 11 月份的 n.label 重叠,因此这些值不合格

Figure 1图1

在此处输入图像描述

Figure 2图 2

在此处输入图像描述

Figure 3图 3

在此处输入图像描述

Figure 4图 4

在此处输入图像描述

Dataframe called 'FID' Dataframe 称为“FID”

structure(list(FID = 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, 28L, 29L, 30L, 31L, 32L, 33L, 34L, 35L, 36L, 
37L, 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, 90L, 91L, 92L, 93L, 94L, 95L, 96L, 97L, 98L, 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, 144L, 145L, 
146L, 147L, 148L, 149L, 150L, 151L, 152L, 153L, 154L, 155L, 156L, 
157L, 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, 205L, 206L, 207L, 208L, 209L, 210L, 211L, 
212L, 213L, 214L, 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, 259L, 260L, 261L, 262L, 263L, 264L, 265L, 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, 303L, 304L, 305L, 306L, 307L, 308L, 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, 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, 505L, 506L, 507L, 508L, 
509L, 510L, 511L, 512L, 513L, 514L, 515L, 516L, 517L, 518L, 519L, 
520L, 521L, 522L, 523L, 524L, 525L, 526L, 527L, 528L, 529L, 530L, 
531L, 532L, 533L, 534L, 535L, 536L, 537L, 538L, 539L, 540L, 541L, 
542L, 543L, 544L, 545L, 546L, 547L, 548L, 549L, 550L, 551L, 552L, 
553L, 554L, 555L, 556L, 557L, 558L, 559L, 560L, 561L, 562L, 563L, 
564L, 565L, 566L, 567L, 568L, 569L, 570L, 571L, 572L, 573L, 574L, 
575L, 576L, 577L, 578L, 579L, 580L, 581L, 582L, 583L, 584L, 585L, 
586L, 587L, 588L, 589L, 590L, 591L, 592L, 593L, 594L, 595L, 596L, 
597L, 598L, 599L, 600L, 601L, 602L, 603L, 604L, 605L, 606L, 607L, 
608L, 609L, 610L, 611L, 612L, 613L, 614L, 615L, 616L, 617L, 618L, 
619L, 620L, 621L, 622L, 623L, 624L, 625L, 626L, 627L, 628L, 629L, 
630L, 631L, 632L, 633L, 634L, 635L, 636L, 637L, 638L, 639L, 640L, 
641L, 642L, 643L, 644L, 645L, 646L, 647L, 648L, 649L, 650L, 651L, 
652L, 653L, 654L, 655L, 656L, 657L, 658L, 659L, 660L, 661L, 662L, 
663L, 664L, 665L, 666L, 667L, 668L, 669L, 670L, 671L, 672L, 673L, 
674L, 675L, 676L, 677L, 678L, 679L, 680L, 681L, 682L, 683L, 684L, 
685L, 686L, 687L, 688L, 689L, 690L, 691L, 692L, 693L, 694L, 695L, 
696L, 697L, 698L, 699L, 700L, 701L, 702L, 703L, 704L, 705L, 706L, 
707L, 708L, 709L, 710L, 711L, 712L, 713L, 714L, 715L, 716L, 717L, 
718L, 719L, 720L, 721L, 722L, 723L, 724L, 725L, 726L, 727L, 728L, 
729L, 730L, 731L, 732L, 733L, 734L, 735L, 736L, 737L, 738L, 739L, 
740L, 741L, 742L, 743L, 744L, 745L, 746L, 747L, 748L, 749L, 750L, 
751L, 752L, 753L, 754L, 755L, 756L, 757L, 758L, 759L, 760L, 761L, 
762L, 763L, 764L, 765L, 766L, 767L, 768L, 769L, 770L, 771L, 772L, 
773L, 774L, 775L, 776L, 777L, 778L, 779L, 780L, 781L, 782L, 783L, 
784L, 785L, 786L, 787L, 788L, 789L, 790L, 791L, 792L, 793L, 794L, 
795L, 796L, 797L, 798L, 799L, 800L, 801L, 802L, 803L, 804L, 805L, 
806L, 807L, 808L, 809L, 810L, 811L, 812L, 813L, 814L, 815L, 816L, 
817L, 818L, 819L, 820L, 821L, 822L, 823L, 824L, 825L, 826L, 827L, 
828L, 829L, 830L, 831L, 832L, 833L, 834L, 835L, 836L, 837L, 838L, 
839L, 840L, 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), Year = c(2015L, 2015L, 2015L, 2015L, 2015L, 
2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 
2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 
2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 
2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 
2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 
2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 
2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 
2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 
2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 
2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 
2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 
2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 
2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 
2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 
2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 
2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 
2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 
2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 
2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 
2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 
2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 
2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 
2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 
2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 
2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 
2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 
2015L, 2015L, 2015L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 
2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 
2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 
2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 
2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 
2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 
2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 
2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 
2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 
2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 
2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 
2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 
2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 
2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 
2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 
2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 
2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 
2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 
2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 
2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 
2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 
2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 
2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 
2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 
2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 
2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 
2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 
2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 
2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 
2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 
2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 
2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 
2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 
2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 
2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 
2016L, 2016L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 
2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 
2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 
2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 
2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 
2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 
2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 
2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 
2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 
2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 
2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 
2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 
2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 
2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 
2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 
2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 
2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 
2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 
2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 
2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 
2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 
2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 
2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 
2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 
2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 
2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 
2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 
2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 
2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 
2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 
2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 
2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 
2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 
2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 
2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 
2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 
2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 
2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 
2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 
2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 
2017L, 2017L, 2017L), Month = structure(c(5L, 5L, 5L, 5L, 5L, 
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 
5L, 5L, 5L, 5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11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 
11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 
11L, 11L, 11L, 11L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 
10L, 10L, 10L, 10L, 10L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 
9L, 9L, 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), .Label = c("April", "August", 
"December", "February", "January", "July", "March", "May", "November", 
"October", "September"), class = "factor")), class = "data.frame", row.names = c(NA, 
-917L))

Dataframe called 'Mean FID': Dataframe 称为“平均 FID”:

structure(list(Year = c(2015, 2016, 2017, 2015, 2016, 2017, 2015, 
2016, 2017, 2015, 2016, 2017, 2015, 2016, 2017, 2015, 2016, 2017, 
2015, 2016, 2017, 2015, 2016, 2017, 2015, 2016, 2017, 2015, 2016, 
2017, 2015, 2016, 2017, 2015, 2016, 2017), Month = structure(c(5L, 
5L, 5L, 4L, 4L, 4L, 8L, 8L, 8L, 1L, 1L, 1L, 9L, 9L, 9L, 7L, 7L, 
7L, 6L, 6L, 6L, 2L, 2L, 2L, 12L, 12L, 12L, 11L, 11L, 11L, 10L, 
10L, 10L, 3L, 3L, 3L), .Label = c("April", "August", "December", 
"February", "January", "July", "June", "March", "May", "November", 
"October", "September"), class = "factor"), Frequency_FID = c(28, 
23, 31, 21, 25, 28, 26, 20, 30, 29, 19, 30, 4, 7, 21, 0, 0, 0, 
0, 7, 7, 16, 30, 26, 9, 29, 27, 14, 31, 22, 8, 25, 28, 24, 24, 
29)), class = "data.frame", row.names = c(NA, -36L))

I don't know gplots so I cannot help you with that, but here is some solution using ggplot2 .我不知道gplots ,所以我无法帮助您,但这里有一些使用ggplot2的解决方案。

ggplot2 is considered by many to be the more versatile R package to make plots. ggplot2被很多人认为是更通用的R package来制作情节。 It is not as straightforward as gplots seems to be, but you usually end up to exactly what you want.它并不像gplots看起来那么简单,但您通常最终会得到您想要的结果。

library(tidyverse) #loads dplyr and ggplot2
month_levels = c('January', 'February', 'March', 'April', 'May', 'June', 
                 'July', 'August', 'September', 'October', 'November', 'December')

data_plot = FID %>% 
  mutate(Month=ordered(Month, levels=month_levels)) %>% #put months in the right order
  group_by(Month) %>% 
  summarise(m=mean(FID), #calculate the summaries you want on the plot
            n_FID=n(),
            sem=sd(FID)/sqrt(n()), 
            ci_low=m-1.96*sem, 
            ci_hi=m+1.96*sem) %>% 
  ungroup()

    
p = ggplot(data_plot, aes(x=Month, y=m, ymin=ci_low, ymax=ci_hi)) +
  geom_line(aes(group=1), size=1) +
  geom_errorbar(width=0.2, color="blue") + 
  geom_point(size=2) + 
  geom_label(aes(y=240, label=paste0("n=", n_FID)))

p
ggsave("p.png", p)

阴谋

You can customize the labels using labs() , xlab or ylab , maybe add facet by year using facet_wrap , and so on.您可以使用labs()xlabylab自定义标签,也可以使用facet_wrap按年份添加分面,等等。 There are gazillions of tutorial to learn about ggplot2 .关于ggplot2有无数的教程可供学习。

Also, there seems to be a bit of misunderstanding in your problem.另外,您的问题似乎有些误解。 n=113 means that there was 113 observation in January (over those 3 years). n=113表示 1 月份(这 3 年)有 113 个观测值。 The mean of all these observation was 307 so your plot might have been correct.所有这些观察的平均值为 307,因此您的 plot 可能是正确的。

I don't think I solved your problem but I hope that helped a tiny bit.我不认为我解决了你的问题,但我希望能有所帮助。

PS:附言:

There might be an error, either in your example sample or in my understanding, as my data_plot has very different values than your data_plot .在您的示例中或在我的理解中可能存在错误,因为我的data_plot与您的data_plot具有非常不同的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM