My question may be stupid but I could not solve by my own. I have a data which show the sports activiy by year from 1995 to 2015 like this
| Year | Sportsactivity (h) |
|---|---|
| 1995 | 300 |
| 1996 | 299 |
| 1997 | 315 |
| 1998 | 286 |
| 1999 | 275 |
| 2000 | 302 |
| 2001 | 304 |
| 2002 | 301 |
| 2003 | 320 |
| 2004 | 342 |
| 2005 | 333 |
| 2006 | 355 |
| 2007 | 370 |
| 2008 | 366 |
| 2009 | 364 |
| 2010 | 362 |
| 2011 | 358 |
| 2012 | 356 |
| 2013 | 354 |
| 2014 | 323 |
| 2015 | 298 |
Now I would like to create a histogram
ggplot(data, aes(x=Year, y=Sportsactivity)) + geom_bar(stat="identity")+
ggtitle("Sportsactivity with rank the year")
How can I add the rank above every year in the bar chart corresponding to the year?
For example 2007 should have the number one above its bar line
>Solution :
A simple solution:
ggplot(data, aes(x=Year, y=Sportsactivity)) +
geom_bar(stat="identity")+
geom_text(aes(label = nrow(data)-rank(Sportsactivity)+1), size = 10, vjust = 2, colour = "white") +
ggtitle("Sportsactivity with rank the year")
