Josh, The code you submitted is not reproducible. I don't have the following objects: barchart, DataToPlot..SeCl, or Colors. However, I think I can answer your questions, with some modified code ...
A rowname can't be a factor. But you can still use a factor to sort the rows of your data for plotting. For example: DataToPlot.. <- data.frame(Location1=c(100, 200), Location2=c(200, 400)) seasons <- factor(c("Fall", "Summer"), levels=c("Summer", "Fall", "Winter", "Spring")) rownames(DataToPlot..) <- as.character(seasons) DataToPlot.. barplot(as.matrix(DataToPlot..)[order(seasons), ], ylab="Average Weekday Counts", col=c("blue", "orange")) Jean LCOG1 <jr...@lcog.org> wrote on 11/29/2012 01:19:20 PM: > > Hi all, > I think this might be an easy one but I cannot think of a way to do this > other than what I am currently attempting. I simply want to sort my data > frame's rownames by a defined vector so that the plots I generate from that > vector are in the desired order > > Consider the test data below: > > #Create test data > DataToPlot.. <- data.frame("Location1" = c(100,200),"Location2" = > c(200,400)) > #Name rowns > rownames(DataToPlot..) <- c("Fall","Summer") > #Attempt to coerce row names to factors > rownames(DataToPlot..) <- as.factor(rownames(DataToPlot..)) > #Attenmpt to sort rownames by defined vector > rownames(DataToPlot..)<- reorder(as.factor(rownames(DataToPlot..)), > new.order = c("Summer","Fall","Winter","Spring")) > > The rownames do not reorder nor do they remain factors. > > Perhaps I can just sort these in the plot? Not sure whats easier/possible? > > barchart(DataToPlot..SeCl , horizontal = FALSE, ylab = "Average Weekday > Counts", > group = colnames(DataToPlot..SeCl ), col = > Colors.[rownames(DataToPlot..SeCl)] ) > > > Thanks for any help. > > Josh [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.