Reputation: 11
V1 V2
1 Undefined E1
2 Undefined E2
3 Undefined E3
4 Undefined E4
5 Undefined E5
6 Undefined E6
7 Undefined E7
8 Undefined E8
Above is a data set I'm trying to plot in R as a bar plot with another 4 datasets. The other 4 have actual data in V1, but this is dataset shows an undefined column. Can anyone help me write something that will allow R to ignore this dataset? For instance, if I had 4 datasets and 2 of them had an "Undefined" in them, R would ignore them and only plot 2 bins? Right now, R is plotting each Undefined as a bin with height of 1. If someone could help just get rid of this bin altogether, that'd be great.
http://oi40.tinypic.com/27zx7oo.jpg
I would like to get rid of that 4th bar in each set altogether. Note that I can't set it to 0, as that is inaccurate. I would like to just avoid it altogether.
k_o_asdf <- read.delim("/Users/asdfman/Combinations/k_open/asdf.state", header=F)
m_o_asdf <- read.delim("/Users/asdfman/Combinations/m_open/asdf.state", header=F)
k_c_asdf <- read.delim("/Users/asdfman/Combinations/k_closed/asdf.state", header=F)
m_c_asdf <- read.delim("/Users/asdfman/Combinations/m_closed/asdf.state", header=F)
d <- data.frame(row.names=c("E1", "E2", "E3", "E4", "E5", "E6", "E7", "E8"), K.Open = c(k_o_asdf$V1), M.Open = c(m_o_asdf$V1), K.Closed = c(k_c_asdfV1), M.Closed = c(m_c_asdf$V1))
d <- do.call(rbind, d)
barplot(d, beside = TRUE,ylim=c(0,2), legend.text = rownames(d),
args.legend = list(x = "topleft", bty="n"))
Thanks very much for the help! If anything's unclear, let me know!
Upvotes: 1
Views: 263
Reputation: 12829
Some suggestions:
You can use row.names=paste0("E", 1:8)
instead of row.names=c("E1", "E2", "E3", "E4", "E5", "E6", "E7", "E8")
.
You can use as.data.frame(t(d))
instead of do.call(rbind, d)
.
To drop the "Undefined" column, try this:
d <- d[,!sapply(d, function(x)all(x=="Undefined"))]
before transposing.
Upvotes: 1