http://stackoverflow.com/questions/21273691/how-to-create-2x2-bar-plot-with-side-by-side-pairwise-bar-in-r/21273993#21273993 http://stackoverflow.com/questions/21274527/how-to-show-all-the-labels-in-x-axis-45-degree-in-r-2x2-bar-plot

dat <- read.table(text="Method  Metric  E0  E1  E2  E4
Method-XXX  Precision   0.9661017   0.9622642   1   0.9655172
Method-YYY  Precision   0.533   0.535   0.378   0.214
Method-ZZZ  Precision  0.595    0.843   0.77    0.689
Method-XZZZ Precision   0.573   0.698   0.53    0.708
Method-XZZZY    Precision   0.008   0.011   0.004   0.002
Method-XXX  Recall  0.9736842   0.9736842   0.9473684   0.9473684
Method-YYY     Recall   1   1   1   0.667
Method-ZZZ  Recall       0.833  1   1   1
Method-XZZZ Recall  1   1   1   1
Method-XZZZY    Recall  0.167   0.75    1   1",header=TRUE)
library(reshape2)
library(ggplot2)

# reshape your data into long format
long <- melt(dat, id=c("Method","Metric"), 
             measure=c("E0","E1","E2","E4"),
             variable = "E.nr")

# make the plot
ggplot(long) +
  geom_bar(aes(x = Method, y = value, fill = Metric), 
           stat="identity", position = "dodge", width = 0.7) +
  facet_wrap(~E.nr) +
  scale_fill_manual("Metric\n", values = c("red","blue"), 
                    labels = c(" Precision", " Recall")) +
  labs(x="",y="") +
  theme_bw() +
  theme(
    panel.grid.major.y = element_line(colour = "black", linetype = 3, size = .5),
    panel.background = element_blank(),
    axis.title.x = element_text(size=16),
    axis.text.x = element_text(size=14, angle=45, hjust=1, vjust=1),
    axis.title.y = element_text(size=16, angle = 90),
    axis.text.y = element_text(size=14),
    strip.background = element_rect(color="white", fill="white"),
    strip.text = element_text(size=16)
  )

When you want to keep axis-labels on each seperate plot, you’ll need the ggplot2 and gridExtra packages.

The code:

dat <- read.table(text="Method  Metric  E0  E1  E2  E4
Method-XXX  Precision   0.9661017   0.9622642   1   0.9655172
Method-YYY  Precision   0.533   0.535   0.378   0.214
Method-ZZZ  Precision  0.595    0.843   0.77    0.689
Method-XZZZ Precision   0.573   0.698   0.53    0.708
Method-XZZZY    Precision   0.008   0.011   0.004   0.002
Method-XXX  Recall  0.9736842   0.9736842   0.9473684   0.9473684
Method-YYY     Recall   1   1   1   0.667
Method-ZZZ  Recall       0.833  1   1   1
Method-XZZZ Recall  1   1   1   1
Method-XZZZY    Recall  0.167   0.75    1   1",header=TRUE)
library(ggplot2)
library(gridExtra)

# making the seperate plots 
pE0 <- ggplot(dat) +
  geom_bar(aes(x = Method, y = E0, fill = Metric), 
           stat="identity", position = "dodge", width = 0.7) +
  scale_fill_manual("Metric\n", values = c("red","blue"), 
                    labels = c(" Precision", " Recall")) +
  labs(title="E0\n",x="",y="") +
  theme_bw() +
  theme(
    panel.grid.major.y = element_line(colour = "black", linetype = 3, size = .5),
    panel.background = element_blank(),
    axis.title.x = element_text(size=16),
    axis.text.x = element_text(size=14, angle=30, hjust=1, vjust=1),
    axis.title.y = element_text(size=16, angle = 90),
    axis.text.y = element_text(size=14)
  )

pE1 <- ggplot(dat) +
  geom_bar(aes(x = Method, y = E1, fill = Metric), 
           stat="identity", position = "dodge", width = 0.7) +
  scale_fill_manual("Metric\n", values = c("red","blue"), 
                    labels = c(" Precision", " Recall")) +
  labs(title="E1\n",x="",y="") +
  theme_bw() +
  theme(
    panel.grid.major.y = element_line(colour = "black", linetype = 3, size = .5),
    panel.background = element_blank(),
    axis.title.x = element_text(size=16),
    axis.text.x = element_text(size=14, angle=30, hjust=1, vjust=1),
    axis.title.y = element_text(size=16, angle = 90),
    axis.text.y = element_text(size=14)
  )

pE2 <- ggplot(dat) +
  geom_bar(aes(x = Method, y = E2, fill = Metric), 
           stat="identity", position = "dodge", width = 0.7) +
  scale_fill_manual("Metric\n", values = c("red","blue"), 
                    labels = c(" Precision", " Recall")) +
  labs(title="E2\n",x="",y="") +
  theme_bw() +
  theme(
    panel.grid.major.y = element_line(colour = "black", linetype = 3, size = .5),
    panel.background = element_blank(),
    axis.title.x = element_text(size=16),
    axis.text.x = element_text(size=14, angle=30, hjust=1, vjust=1),
    axis.title.y = element_text(size=16, angle = 90),
    axis.text.y = element_text(size=14)
  )

pE4 <- ggplot(dat) +
  geom_bar(aes(x = Method, y = E4, fill = Metric), 
           stat="identity", position = "dodge", width = 0.7) +
  scale_fill_manual("Metric\n", values = c("red","blue"), 
                    labels = c(" Precision", " Recall")) +
  labs(title="E4\n",x="",y="") +
  theme_bw() +
  theme(
    panel.grid.major.y = element_line(colour = "black", linetype = 3, size = .5),
    panel.background = element_blank(),
    axis.title.x = element_text(size=16),
    axis.text.x = element_text(size=14, angle=30, hjust=1, vjust=1),
    axis.title.y = element_text(size=16, angle = 90),
    axis.text.y = element_text(size=14)
  )

# function to extract the legend (borrowed from: https://github.com/hadley/ggplot2/wiki/Share-a-legend-between-two-ggplot2-graphs )
g_legend<-function(a.gplot){
  tmp <- ggplot_gtable(ggplot_build(a.gplot))
  leg <- which(sapply(tmp$grobs, function(x) x$name) == "guide-box")
  legend <- tmp$grobs[[leg]]
  return(legend)}

legend <- g_legend(pE1)
lwidth <- sum(legend$width)

# combining the plots with gridExtra
grid.arrange(arrangeGrob(pE0 + theme(legend.position="none"),
                         pE1 + theme(legend.position="none"),
                         pE2 + theme(legend.position="none"),
                         pE4 + theme(legend.position="none")
                         ), nrow=1)

dat <- read.table(text="Method  Metric  E0  E1  E2  E4
M1  Precision   0.9661017   0.9622642   1   0.9655172
M2  Precision   0.533   0.535   0.378   0.214
M1  Recall  0.9736842   0.9736842   0.9473684   0.9473684
M2  Recall  1   1   1   0.667",header=TRUE)
##Define a layout and some colours:
layout(matrix(c(1,2,5,3,4,5),nrow=2,byrow = TRUE))
barcols <- c("red","blue")
sapply(3:6, 
  function(x) {
    bp <- barplot(matrix(dat[,x],nrow=2,byrow=TRUE),beside=TRUE,col=barcols)
    title(main=names(dat[x]))
    axis(1,at=colMeans(bp),c("M1","M2"),lwd=0,lwd.tick=1)
    abline(h=0)
  }
)
## [[1]]
## NULL
## 
## [[2]]
## NULL
## 
## [[3]]
## NULL
## 
## [[4]]
## NULL
plot(NA,xlim=c(0,1),ylim=c(0,1),ann=FALSE,axes=FALSE)
legend(0,0.6,c("Precision","Recall"),fill=barcols,cex=1.5)

ggplot2 was designed to make this easy.

library(ggplot2)
library(reshape2)
dat <- read.table(text="Method  Metric  E0  E1  E2  E4
M1  Precision   0.9661017   0.9622642   1   0.9655172
M2  Precision   0.533   0.535   0.378   0.214
M1  Recall  0.9736842   0.9736842   0.9473684   0.9473684
M2  Recall  1   1   1   0.667",header=TRUE)
gg <- melt(dat,id=1:2)
ggplot(gg) +
  geom_bar(aes(x=Method, y=value, fill=Metric), stat="identity",
           position="dodge")+facet_wrap(~variable)

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.