x <- rnorm(30, mean=15, sd=5)
y <- rnorm(30, mean=25, sd=5)
grupo1 <- gl(2, 30, length = 60, labels = c("Grupo a", "Grupo b"))
newdata <- data.frame(c(x,y), grupo1)
names(newdata)[1] <- "Valor"
names(newdata)[2] <- "Grupo"
head(newdata)
## Valor Grupo
## 1 11.379719 Grupo a
## 2 6.197039 Grupo a
## 3 12.475231 Grupo a
## 4 13.047476 Grupo a
## 5 16.751823 Grupo a
## 6 17.046309 Grupo a
str(newdata)
## 'data.frame': 60 obs. of 2 variables:
## $ Valor: num 11.4 6.2 12.5 13 16.8 ...
## $ Grupo: Factor w/ 2 levels "Grupo a","Grupo b": 1 1 1 1 1 1 1 1 1 1 ...
MediaValor <- tapply(newdata$Valor, newdata$Grupo, mean)
MediaValor
## Grupo a Grupo b
## 14.65945 24.56261
library(gplots)
##
## Attaching package: 'gplots'
##
## The following object is masked from 'package:stats':
##
## lowess
abajo <- tapply(newdata$Valor, newdata$Grupo, function(v) t.test(v)$conf.int[1])
arriba <- tapply(newdata$Valor, newdata$Grupo, function(v) t.test(v)$conf.int[2])
```
par(mfrow=c(1,1)) #filas,columnas
par(mar=c(5,5,3,2)+0.1) #margenes
barplot2(MediaValor, plot.ci=T,
ci.l=abajo, ci.u=arriba,
main = "Figure x. Average (95% CI) of xxx" ,
xlab= "X lab" , ylab= "y lab" ,
ylim=c(0, 30),
col="white")
text(x=1.3, y=29, labels="p<0.001")
arrows(x = 1.1, y = 29, x1=.7, y1= 29 , length = 0.05, angle = 90,
code = 2, col = par("fg"), lty = par("lty"),
lwd = par("lwd"))
arrows(x=1.5, y= 29, x1 = 1.9, y1 = 29 , length = 0.05, angle = 90,
code = 2, col = par("fg"), lty = par("lty"),
lwd = par("lwd"))