R 生成箱线图时出现新错误

R 生成箱线图时出现新错误,r,ggplot2,error-handling,R,Ggplot2,Error Handling,所以我昨天让这个脚本在另一个数据集上运行,它实际上在这个数据集上运行过一次,但是当我尝试使用plot_grid将它与另一个图形组合时,我得到了以下错误: 错误: T_SHOW_BACKTRACE environmental variable. Error in grid.Call(L_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : polygon edge not found 现在,当我试图构建箱线图本身时,我得到了相同的错误 以下

所以我昨天让这个脚本在另一个数据集上运行,它实际上在这个数据集上运行过一次,但是当我尝试使用plot_grid将它与另一个图形组合时,我得到了以下错误:

错误:

T_SHOW_BACKTRACE environmental variable.
Error in grid.Call(L_textBounds, as.graphicsAnnot(x$label), x$x, x$y,  : 
  polygon edge not found
现在,当我试图构建箱线图本身时,我得到了相同的错误

以下是我的数据:

dput(SUICMass)
structure(list(ChillTime = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 
3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 5L, 
5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 7L, 7L, 
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L), .Label = c("2", "4", "6", "24", 
"27", "29", "31"), class = "factor"), Mass = c(1.2687, 1.5417, 
1.6898, 1.7655, 2.413, 2.0333, 2.0824, 1.2676, 1.4916, 2.1585, 
2.2453, 1.3624, 1.2951, 2.4209, 2.0804, 1.9227, 1.9032, 2.1063, 
1.7601, 1.9905, 1.9837, 1.6312, 1.8567, 1.4433, 1.9369, 2.1029, 
2.0265, 1.3212, 1.2971, 1.5823, 1.4759, 1.2745, 0.714, 1.5693, 
1.7906, 1.8607, 1.8851, 1.9192, 1.6307, 1.4269, 1.7011, 0.8249, 
1.7198, 1.3939, 1.394, 2.1527, 1.288, 1.4724, 1.5264, 1.6562, 
1.5796, 1.4982, 1.2794, 1.6021, 0.6345, 2.4041, 2.0246, 1.8398, 
1.349, 2.0156, 1.1563, 2.0462)), .Names = c("ChillTime", "Mass"
), row.names = c(NA, -62L), class = "data.frame")
这是我的密码:

library(ggplot2)
library(multcompView)
library(plyr)
library(gridExtra)
library(cowplot)

## Box plot for Susans WMA population
SUICMass <- read.csv('SUICMass_Test_June_28_2017.csv', header = TRUE)
SUICMass$ChillTime <- factor(SUICMass$ChillTime, levels=c("2", "4", "6", "24", "27", "29", "31"))


generate_label_df <- function(SUICMassTUKEY, variable){

  # Extract labels and factor levels from Tukey post-hoc 
  Tukey.levels <- SUICMassTUKEY[[variable]][,4]
  Tukey.labels <- data.frame(multcompLetters(Tukey.levels)['Letters'])

  #I need to put the labels in the same order as in the boxplot :
  Tukey.labels$treatment=rownames(Tukey.labels)
  Tukey.labels=Tukey.labels[order(Tukey.labels$treatment) , ]
  return(Tukey.labels)
}

SUICMassmodel=lm(SUICMass$Mass~SUICMass$ChillTime )
SUICMassANOVA=aov(SUICMassmodel)

# Tukey test to study each pair of treatment :
SUICMassTUKEY <- TukeyHSD(x=SUICMassANOVA, 'SUICMass$ChillTime', conf.level=0.95)

labels<-generate_label_df(SUICMassTUKEY , "SUICMass$ChillTime")#generate labels using function

names(labels)<-c('Letters','ChillTime')#rename columns for merging

SUICMassyvalue<-aggregate(.~ChillTime, data=SUICMass, max)# obtain letter position for y axis using means

SUICMassfinal<-merge(labels,SUICMassyvalue) #merge dataframes

SUICMassPlot <- ggplot(SUICMass, aes(x = ChillTime, y = Mass)) +
  stat_boxplot(geom ='errorbar', width=.2) +
  geom_blank() +
  theme_bw() +
  theme(panel.border = element_rect(fill=NA, colour = "black", size=0.75)) +
  theme(axis.text.x = element_text(face="bold")) +
  theme(axis.text.y = element_text(face="bold")) +
  labs(x = 'Time (weeks)', y = 'Mass (g)') +
  ggtitle(expression(atop(bold("Fresh Mass"), atop(italic("(Sarah's - UIC Colony)"))))) +
  theme(plot.title = element_text(hjust = 0.5, vjust = -0.6, face='bold')) +
  geom_boxplot(fill = 'dodgerblue1', stat = "boxplot") +
  geom_text(data = SUICMassfinal, aes(x = ChillTime, y = Mass, label = Letters),vjust=-2,hjust=.5) +
  scale_y_continuous(limit = c(0, 3.5))
库(ggplot2)
库(multcompView)
图书馆(plyr)
图书馆(gridExtra)
图书馆(cowplot)
##Susans WMA人口的方框图

SUICMass你的代码对我来说很有用,而且做了一个漂亮的方块图。您是否尝试重新启动R?这似乎是ggtitle(表达式(顶部(粗体(“新鲜质量”)、顶部(斜体(((Sarah's-UIC Colony)”)))的问题+如果没有这个命令,代码运行得很好。你的代码对我很有效,并且绘制了一个漂亮的方框图。您尝试重新启动R了吗?这似乎是ggtitle(表达式(顶部(粗体(“新鲜质量”))、顶部(斜体(((Sarah's-UIC Colony)”)))))+代码在没有该命令的情况下运行正常。