如何以argumnet的形式给出Y轴的极限和断点

如何以argumnet的形式给出Y轴的极限和断点,r,ggplot2,R,Ggplot2,我编写了一个R脚本,它以数据文件名为参数并生成一个图形。我想给出y轴极限和break作为参数,但得到了以下错误 Error in del/by : non-numeric argument to binary operator Calls: scale_y_continuous ... continuous_scale -> check_breaks_labels -> s eq -> seq.default 显然,我的脚本在这里寻找数字 scale_y_continu

我编写了一个R脚本,它以数据文件名为参数并生成一个图形。我想给出y轴极限和break作为参数,但得到了以下错误

Error in del/by : non-numeric argument to binary operator
Calls: scale_y_continuous ... continuous_scale -> check_breaks_labels -> s    eq -> seq.default
显然,我的脚本在这里寻找数字

scale_y_continuous(expand=c(0,0), limits = c(0, args[4]),breaks = seq(0, args[4], by = args[5]))
这个问题有解决办法吗

我的数据文件如下所示

> Data2
  treatment N     value        sd        se        ci
1        AL 3 2.4066667 0.3950105 0.2280594 0.9812606
2        BL 3 5.8000000 1.0023971 0.5787343 2.4900925
3        CL 3 0.7333333 0.2516611 0.1452966 0.6251609
而脚本如下

#!/usr/bin/env Rscript
args = commandArgs(trailingOnly=TRUE)
# test if there is at least one argument: if not, return an error
if (length(args)==0) {
  stop("At least one argument must be supplied (input file).\n", call.=FALSE)
} else if (length(args)==1) {
  # default output file
  args[2] = "out.png"
}


library(Rmisc) 
library(ggplot2)

Data2 <- read.csv(args[1], header=T)
source("https://gist.githubusercontent.com/sanjaysingh765/fcfaf58e2de7874a9c646097fe4c5c38/raw/ggplot2_theme2.R")

# create graph
png(args[2], units="in", family="Times New Roman",  width=1.2, height=1.2, res=300, pointsize = 2) #pointsize is font size| increase image size to see the key
ggplot(Data2, aes(x=treatment, y=value, fill=Data2$treatment))+
geom_bar(colour="black",stat="identity",position=position_dodge(),size=.1,width=.5) + 
geom_errorbar(aes(ymax=value+se, ymin=value-se),width=0.1, size=0.2, color="black")+
scale_fill_brewer(palette="Set3",guide=FALSE) +
ggtitle(args[3])+
labs(y="Relative expression",x="")+
scale_y_continuous(expand=c(0,0), limits = c(0, args[4]),breaks = seq(0, args[4], by = args[5]))+
theme_ms()

dev.off()
#/usr/bin/env Rscript
args=commandArgs(trailingOnly=TRUE)
#测试是否至少有一个参数:如果没有,则返回错误
if(长度(args)==0){
停止(“必须至少提供一个参数(输入文件)。\n”,call.=FALSE)
}else if(长度(args)==1){
#默认输出文件
args[2]=“out.png”
}
图书馆(Rmisc)
图书馆(GG2)

Data2首先需要将参数转换为数值。args-是一个字符向量。尝试:

  ggplot(Data2, aes(x=treatment, y=value, fill=Data2$treatment))+
  geom_bar(colour="black",stat="identity",position=position_dodge(),size=.1,width=.5) + 
  geom_errorbar(aes(ymax=value+se, ymin=value-se),width=0.1, size=0.2, color="black")+
  scale_fill_brewer(palette="Set3",guide=FALSE) +
  ggtitle(as.numeric(args[3]))+
  labs(y="Relative expression",x="")+
  scale_y_continuous(expand=c(0,0), 
                     limits = c(0, as.numeric(args[4])),
                     breaks = seq(0, as.numeric(args[4]), by = as.numeric(args[5])))+
  theme_ms()