0

I want to adjust the tickmarks so I can get a nice printout of my data.

Here is my code and an added barplot

> data
   Attributes Year Contribution rank
2           a 2014        0.211    2
1           a 2013        0.188    1
3           b 2013        0.160    3
4           b 2014        0.160    4
5           d 2013        0.152    5
7           c 2013        0.150    7
6           c 2014        0.146    6
9           e 2013        0.145    9
8           d 2014        0.139    8
10          e 2014        0.121   10
12          f 2014        0.117   12
11          f 2013        0.110   11
14          g 2014        0.079   14
13          g 2013        0.063   13


#fix for sorting the Attributes in order to plot in a sorted way

data <- data[with(data,order(-Contribution)), ] ## Sorting
data$Attributes <- ordered(data$Attributes, levels=levels(data$Attributes)[unclass(data$Attributes)])

ggplot(data, aes(Attributes, Contribution)) + geom_bar(aes(Attributes, fill = Year), position = "dodge", stat="identity") + coord_flip() +
  scale_fill_manual(values=c("#016c59","#02818a"))  +  coord_flip() + xlim(rev(levels(data$Attributes))) 

This code produces the plot: enter image description here

I would like to have even spacing on the Attribute axis, any ideas??

jonas
  • 13,559
  • 22
  • 57
  • 75
  • I'm reading your data frame with `read.table`, converting Attributes and Year to factors, and the `ggplot` call works fine. Try that once again in a clean session and post `sessionInfo()` if that does not help. – tonytonov Nov 28 '14 at 12:46
  • Plotting works, however the spacing on the attributes axis is not even... – jonas Nov 28 '14 at 13:07
  • By "fine" I meant "evenly spaced", as one would expect. – tonytonov Nov 28 '14 at 13:08
  • somthing with my ordering screws things up in ggplot...hmmm – jonas Nov 28 '14 at 13:10
  • withot the ordering I can not figure out how to plot the attributes in descendin´g order of the ranking...the coord_flip() rearranges the sorting somhow I suspect – jonas Nov 28 '14 at 13:12
  • There are many questions on how to display factor ordering correctly with ggplot, e.g. [here](http://stackoverflow.com/questions/8713462/ggplot2-change-order-of-display-of-a-factor-variable-on-an-axis). Try rewriting that `ordered` + `unclass` line, it looks overcomplicated. – tonytonov Nov 28 '14 at 13:18

0 Answers0