marzo 03, 2013

Gráfico de barras ± CI en R


Gráficos de barra con errores estándares o intervalos de confidencia son comunes en publicaciones científicas. En este sitio http://gallery.r-enthusiasts.com/graph/barplot2_:_Enhanced_Bar_Plots_54 encontrare un ejemplo de códigos.

# Example with confidence intervals and grid
# upload gplots, gdata, gtools, and caTools packages
library(gplots)
Warning: package 'gplots' was built under R version 3.0.1
Loading required package: gtools
Loading required package: gdata
gdata: Unable to locate valid perl interpreter gdata: gdata: read.xls()
will be unable to read Excel XLS and XLSX files gdata: unless the 'perl='
argument is used to specify the location gdata: of a valid perl
intrpreter. gdata: gdata: (To avoid display of this message in the future,
please gdata: ensure perl is installed and available on the executable
gdata: search path.)
gdata: Unable to load perl libaries needed by read.xls() gdata: to support
'XLX' (Excel 97-2004) files.
gdata: Unable to load perl libaries needed by read.xls() gdata: to support
'XLSX' (Excel 2007+) files.
gdata: Run the function 'installXLSXsupport()' gdata: to automatically
download and install the perl gdata: libaries needed to support Excel XLS
and XLSX formats.
Attaching package: 'gdata'
The following object is masked from 'package:stats':

nobs
The following object is masked from 'package:utils':

object.size
Loading required package: caTools
Warning: package 'caTools' was built under R version 3.0.1
Loading required package: grid
Loading required package: KernSmooth
KernSmooth 2.23 loaded Copyright M. P. Wand 1997-2009
Loading required package: MASS
Attaching package: 'gplots'
The following object is masked from 'package:stats':

lowess
hh <- t(VADeaths)[, 5:1]
mybarcol <- "gray20"
ci.l <- hh * 0.85
ci.u <- hh * 1.15
mp <- barplot2(hh, beside = TRUE,
               col = c("lightblue", "mistyrose",
                       "lightcyan", "lavender"),
               legend = colnames(VADeaths), ylim = c(0, 100),
               main = "Tasa de decesos en Virginia", font.main = 4,
               sub = "Faked 95 percent error bars", col.sub = mybarcol,
               cex.names = 1.5, plot.ci = TRUE, ci.l = ci.l, ci.u = ci.u,
               plot.grid = TRUE)
mtext(side = 1, at = colMeans(mp), line = 2,
      text = paste("Mean", formatC(colMeans(hh))), col = "red")
box()
plot of chunk unnamed-chunk-1


Fuente: R Graph Gallery. Barplot2: enhanced Bar Plots http://gallery.r-enthusiasts.com/graph/barplot2_:_Enhanced_Bar_Plots_54






No hay comentarios.: