我有一个数据框列表,正在使用ggplot为每个图绘制列图。我可以绘制图,但是在添加轴标签时遇到了麻烦。
这是我到目前为止拥有的代码(有效):
library("ggplot2")
zz.dat <- structure(list(exp.mean = c(5.1, 4.9, 4.7, 4.6, 5, 5.4), se = c(0.2,
0.2, 0.2, 0.2, 0.2, 0.4), species = structure(c(1L, 1L, 1L, 2L,
2L, 2L), .Label = c("a", "b"), class = "factor"), target = structure(c(1L,
2L, 3L, 1L, 2L, 3L), .Label = c("gg", "hh", "ii"), class = "factor")),
class = "data.frame", row.names = c("1",
"2", "3", "4", "5", "6"))
zz.plot <- split(zz.dat, zz.dat$target)
p <- lapply(zz.plot,
function(d) ggplot(data=d, aes(x=species, y=exp.mean, color=species, fill=species)) +
geom_col() +
geom_errorbar(aes(ymin = exp.mean-se, ymax = exp.mean+se), width=0.2))
这些地块将带有平均值和种类的标签。我试图在lapply ggplot函数中添加y轴标签:
p <- lapply(zz.plot,
function(d) ggplot(data=d, aes(x=species, y=exp.mean, color=species, fill=species)) +
geom_col() +
geom_errorbar(aes(ymin = exp.mean-se, ymax = exp.mean+se), width=0.2)) +
ylab("Relative Gene Expression")
给出了错误
Error in lapply(qpcr_plot, function(d) ggplot(data = d, aes(x = Sample.Name, :
non-numeric argument to binary operator
然后我尝试使用for循环为每个图分别添加y标签:
for(i in 1:length(p)){
r[i] <- p[i] + ylab("Relative Gene Expression")
print(r[i])
}
这给了我同样的错误。