你可以做基础R图形任何东西,如果你知道这种API。
## define data
x <- 0:14;
dat <- list(
Sentinel=list(
mean=c(-0.95,-0.15,-0.40,-0.10,-1.30,-0.95,-1.10,-0.60,-1.10,-1.20, 0.30,-0.50,-2.60, 0.10,-0.95),
sd =c(0.55, 0.55, 1.40, 0.25, 0.60, 1.20, 0.40, 1.00, 0.80, 0.15, 0.25, 0.22, 0.52, 0.30, 1.50),
pch=22L, pt.cex=1.7, pt.lwd=2.5, pt.bg='white'
),
Infected=list(
mean=c(-1.35, 0.50,-0.26,-0.05,-0.40,-0.94, 0.55, 0.55,-0.48, 0.23,-1.30,-0.23,-1.05, 0.40, 0.20),
sd =c(0.70, 0.15, 0.70, 0.27, 0.87, 0.50, 0.80, 0.70, 0.50, 0.28, 0.40, 0.45, 1.02, 0.45, 0.35),
pch=21L, pt.cex=1.4, pt.lwd=2.5, pt.bg='#5555BB'
)
);
## plot parameters
xoff <- 1;
xlim <- c(0-xoff,14+xoff);
ylim <- c(-4,2);
xticks <- seq(x[1L],x[length(x)],2);
yticks <- -4:2;
datline.lwd <- 2;
err.spread <- 0.12;
err.lwd <- 2.2;
err.col <- '#777777';
## helper function
errorbar <- function(x,mean,sd) {
segments(x,mean-sd,y1=mean+sd,lwd=err.lwd,col=err.col);
segments(x-err.spread,mean-sd,x1=x+err.spread,lwd=err.lwd,col=err.col);
segments(x-err.spread,mean+sd,x1=x+err.spread,lwd=err.lwd,col=err.col);
}; ## end errorbar()
## plot
plot(NA,xlim=xlim,ylim=ylim,xaxs='i',yaxs='i',axes=F,ann=F);
for (prop in names(dat)) {
d <- dat[[prop]];
lines(x,d$mean,lwd=datline.lwd);
errorbar(x,d$mean,d$sd);
points(x,d$mean,pch=d$pch,cex=d$pt.cex,lwd=d$pt.lwd,bg=d$pt.bg);
}; ## end for
axis(1L,xticks,cex.axis=1.3,lwd=3,col='#777777');
mtext('Days post Infection-Aerosol Group',1L,2.3,cex=1.47);
axis(2L,yticks,cex.axis=1.3,lwd=3,col='#777777',las=1L);
mtext('Change in Temperature (Fahrenheit)',2L,2.3,cex=1.47);
rect(xlim[1L],ylim[1L],xlim[2L],ylim[2L],lwd=4,border='#777777',xpd=NA);
lp <- c('pch','pt.cex','pt.lwd','pt.bg');
do.call(legend,c(list(11.7,1.7,names(dat),bty='n',adj=0.1,lwd=datline.lwd),setNames(nm=lp,lapply(lp,function(p) sapply(dat,`[[`,p)))));
你的新的随机测试数据涵盖范围不同,所以我们要调整一些东西,使绘图代码工作。
## OP's new randomized input
set.seed(23L);
N <- 5L;
data <- data.frame(group1=rnorm(N,100,5),group2=rnorm(N,100,5),group1.se=runif(N,0.5,3),group2.se=runif(N,0.5,3));
## transfer to dat
x <- seq_len(nrow(data))-1L;
dat <- list(
group1=list(
mean=data$group1,
sd =data$group1.se,
pch=22L, pt.cex=1.7, pt.lwd=2.5, pt.bg='white'
),
group2=list(
mean=data$group2,
sd =data$group2.se,
pch=21L, pt.cex=1.4, pt.lwd=2.5, pt.bg='#5555BB'
)
);
## plot parameters
xoff <- 1;
xlim <- c(x[1L]-xoff,x[length(x)]+xoff);
ylim <- c(95,113);
xticks <- seq(x[1L],x[length(x)]);
yticks <- seq(ylim[1L],ylim[2L]);
datline.lwd <- 2;
err.spread <- 0.12;
err.lwd <- 2.2;
err.col <- '#777777';
## helper function
errorbar <- function(x,mean,sd) {
segments(x,mean-sd,y1=mean+sd,lwd=err.lwd,col=err.col);
segments(x-err.spread,mean-sd,x1=x+err.spread,lwd=err.lwd,col=err.col);
segments(x-err.spread,mean+sd,x1=x+err.spread,lwd=err.lwd,col=err.col);
}; ## end errorbar()
## plot
plot(NA,xlim=xlim,ylim=ylim,xaxs='i',yaxs='i',axes=F,ann=F);
for (prop in names(dat)) {
d <- dat[[prop]];
lines(x,d$mean,lwd=datline.lwd);
errorbar(x,d$mean,d$sd);
points(x,d$mean,pch=d$pch,cex=d$pt.cex,lwd=d$pt.lwd,bg=d$pt.bg);
}; ## end for
axis(1L,xticks,cex.axis=1.3,lwd=3,col='#777777');
mtext('Days',1L,2.3,cex=1.47);
axis(2L,yticks,cex.axis=1.3,lwd=3,col='#777777',las=1L);
mtext('Weight',2L,2.7,cex=1.47);
rect(xlim[1L],ylim[1L],xlim[2L],ylim[2L],lwd=4,border='#777777',xpd=NA);
lp <- c('pch','pt.cex','pt.lwd','pt.bg');
do.call(legend,c(list(3.7,99,names(dat),bty='n',adj=0.1,lwd=datline.lwd),setNames(nm=lp,lapply(lp,function(p) sapply(dat,`[[`,p)))));
[你尝试过这么远吗?(http://whathaveyoutried.com) 请[编辑]你的问题以显示你是有问题的代码 一个[MCVE]那么我们可以尝试帮助 解决具体问题。你还应该阅读[问]。 –