I’m working on a data visualization project and am making some line graphs. This is my data set:
groupA <- read.csv("afcongroupA.csv", header=T, row.names=NULL)
groupA
Date Team Position
1 1/12 South Africa 56
2 1/12 Angola 85
3 1/12 Morocco 61
4 1/12 Cape Verde Islands 58
5 4/12 South Africa 71
6 4/12 Angola 78
7 4/12 Morocco 62
8 4/12 Cape Verde Islands 76
9 8/12 South Africa 67
10 8/12 Angola 85
11 8/12 Morocco 68
12 8/12 Cape Verde Islands 78
13 12/12 South Africa 87
14 12/12 Angola 84
15 12/12 Morocco 72
16 12/12 Cape Verde Islands 69
I then plotted them on a line graph to show the rise of decline in position standings:
groupA$Date <- factor(groupA$Date, levels=groupA$Date[!duplicated(groupA$Date)])
ggplot(groupA, aes(x=Date, y=Position, colour=Team, group=Team)) + geom_line()
What I want to do is reverse the y-axis so that the largest number is at the bottom. I tried this bit of code:
groupA <- coord_flip() + scale_x_reverse()
But I get this error message:
Error in coord_flip() + scale_x_reverse() :
non-numeric argument to binary operator
I’m using R 2.15.2 on a Mac running OS X.
As your column
Dateis a factor thenscale_x_reverse()won’t work. One solution is to order your levels of factors in data frameThen just use your code to make plot and flip axis.