Hi:
This works for me:
# Note the na.strings = argument...
scores <- read.table(header = TRUE, na.strings = "-", text = "
Subject Student_A Student_B Student_C Student_D Student_E
1 Art 10 1 5 3 2
2 Science 1 10 5 4 8
3 History 8 5 7 1 1
4 Sport 2 9 5 10 4
5 Physics - 1 2 3 1
6 English 2 8 6 8 5
7 Chemistry 4 2 1 1 4
8 Mathematics 10 2 5 4 2
")
library(reshape2)
library(ggplot2)
scores2<- melt(scores, id=c("Subject"))
> str(scores2)
'data.frame': 40 obs. of 3 variables:
$ Subject : Factor w/ 8 levels "Art","Chemistry",..: 1 7 4 8 6 3 2 5 1 7 ...
$ variable: Factor w/ 5 levels "Student_A","Student_B",..: 1 1 1 1 1 1 1 1 2 2 ...
$ value : int 10 1 8 2 NA 2 4 10 1 10 ...
# Note that scores2$value is integer - my guess is that
# in your version, value is a factor.
ggplot(scores2, aes(x = Subject, y = value, fill=variable)) +
geom_bar(stat="identity", position=position_dodge(), colour="black") +
xlab("Subject") + ylab("Scores") +
ggtitle("Rank of Student Scores by Subject") +
coord_flip()
I just liked the coord_flip() version better because it avoids labeling issues. YMMV.
Dennis