p_boxplot_exp_mt.gene = boxplot(sample_exp_mt.gene) > p_boxplot_exp_mt.gene = p_boxplot_exp_mt.gene + + geom_boxplot(color = "black", size = 0.25, outlier.shape = NA) + + xlab(NULL) + ylab("log2(CPM+1)") + + scale_color_manual(values = "black") + + stat_summary(fun = max, geom = "crossbar", color = "black", width = 0.1) + + stat_summary(fun = min, geom = "crossbar", color = "black", width = 0.1) + + theme(axis.line = element_line(color = "black", size = 0.25), + axis.ticks = element_line(color = "black", size = 0.25), + axis.text = element_text(color = "black", angle = 90, size = 18), + axis.title = element_text(color = "black", size = 18)) + + geom_text(data = sample_exp_mt.gene, aes(x = sample, y = median_expression, + label = paste0("Median: ", round(median_expression, 2))), + vjust = -1, hjust = -0.5, size = 4, color = "black")+ + theme(panel.background = element_blank()) Error in p_boxplot_exp_mt.gene + geom_boxplot(color = "black", size = 0.25, : non-numeric argument to binary operator
时间: 2024-03-19 15:43:51 浏览: 133
看起来您的代码中有一些问题,主要是在 `p_boxplot_exp_mt.gene = boxplot(sample_exp_mt.gene)` 这行代码中,您将 `boxplot` 的输出结果赋值给了 `p_boxplot_exp_mt.gene` 变量。但是,在后面的代码中,您却又将 `p_boxplot_exp_mt.gene` 作为一个 `ggplot` 对象进行操作,这就导致了一个类型不匹配的错误。
建议您将 `boxplot` 的输出结果转换为一个数据框,再使用 `ggplot` 进行绘图,如下所示:
```
# 将 boxplot 的输出结果转换为数据框
df_boxplot <- as.data.frame(p_boxplot_exp_mt.gene)
# 使用 ggplot 绘制箱线图
ggplot(df_boxplot, aes(x = "", y = sample_exp_mt.gene)) +
geom_boxplot(color = "black", size = 0.25, outlier.shape = NA) +
xlab(NULL) +
ylab("log2(CPM+1)") +
scale_color_manual(values = "black") +
stat_summary(fun = max, geom = "crossbar", color = "black", width = 0.1) +
stat_summary(fun = min, geom = "crossbar", color = "black", width = 0.1) +
theme(axis.line = element_line(color = "black", size = 0.25),
axis.ticks = element_line(color = "black", size = 0.25),
axis.text = element_text(color = "black", angle = 90, size = 18),
axis.title = element_text(color = "black", size = 18)) +
geom_text(data = df_boxplot, aes(x = 1, y = median,
label = paste0("Median: ", round(median, 2))),
vjust = -1, hjust = -0.5, size = 4, color = "black") +
theme(panel.background = element_blank())
```
这样可以避免 `p_boxplot_exp_mt.gene` 类型不匹配的错误。
阅读全文