Your problem seem to come down to wrong data formatting. You need to make a matrix with the right row names structure to create plot that you want with base graphics. Here is your solution:
#your data...
d <- data.frame(row.names=c("1-2","2-3","3-4"), abc = c(10,80, 30),
def = c(15, 95, 55), ghi = c(20, 10, 80))
#but you make a matrix out of it to create bar chart
d <- do.call(rbind, d)
#...and you are sorted
barplot(d, beside = TRUE, ylim=c(0,100), legend.text = rownames(d),
args.legend = list(x = "topleft", bty="n"))
However, I sometimes like to use lattice
for this kind of task. This time you don't even have to make matrix, you just keep your data.frame
in original format:
d <- data.frame(column1=rep(c("1-2","2-3","3-4"), each=3),
column2=rep(c("abc", "def", "ghi"), 3),
column3=c(10, 15, 20, 80, 95, 10, 30, 55, 80))
require(lattice)
barchart(column3 ~ column1, groups=column2, d, auto.key = list(columns = 3))
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…