0

I've searched through numerous tutorials, but cannot seem to crack what should be a basic couple of commands in R.

I'm trying to create a grouped barplot in ggplot2 using mean percentage data from 11 categories (variable: 0 to 10, which represent the number of times a salmon stream was enumerated) for two time periods (1 & 2: Before & After).

My basic data are as follows:

period 1 = (0)7.5, (1)2.9, (2)6.8, (3)3.9, (4)4.1, (5)7.7, (6)4.4, (7)8.7, (8)10.8, (9)14.5, (10)28.8;
period 2 = (0)8.7, (1)2.5, (2)2.7, (3)6.5, (4)8.3, (5)7.9, (6)6.5, (7)8.8, (8)13.1, (9)13.7, (10)21.3;

The code I have used thus far to produce the paired barplot is:

ggplot(data=data, aes(x=variable, y=value, fill=factor(period))) +
 geom_bar(stat="identity", position="dodge") +
 scale_fill_discrete(name="Period", breaks=c(1,2), labels=c("Before WSP", "After WSP")) +
 xlab("Monitoring effort") +
 ylab("Mean percentage")

which produces

/Users/price/Desktop/paired barplot.pdf

My question is, how do I change the x-axis ticks so that they all show (0 to 10....not simply "0", "2.5", etc.) and are not in decimals but whole numbers, and how do I change the colour of my bars to grey scale without disturbing the "fill" command of my legend?

Grateful for your help

Sandy Muspratt
  • 31,719
  • 12
  • 116
  • 122
  • [Here are some tips](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) on how to add example datasets to questions. – aosmith Nov 29 '16 at 14:15

1 Answers1

0

I am not quite sure what you want.

I adapated your ggplot code like this:

ggplot(data=data, aes(x=measure, y=value, fill=factor(timestamp))) +
  geom_bar(stat="identity", position="dodge") +
  xlab("Monitoring effort") +
  ylab("Mean percentage") + 
  scale_fill_manual(values = c("#aeaeae", "#0a0a0a"), labels=c("Before WSP", "After WSP")) + 
  scale_y_continuous(breaks = seq(0,30,by=5))

which produces this plot: enter image description here

Note scale_y_continuous with the breaks specified and scale_fill_manual with the colours.

this is the data:

     measure timestamp value
1   measure1     time1   7.5
2   measure2     time1   2.9
3   measure3     time1   6.8
4   measure4     time1   3.9
5   measure5     time1   4.1
6   measure6     time1   7.7
7   measure7     time1   4.4
8   measure8     time1   8.7
9   measure9     time1  10.8
10 measure10     time1  14.5
11 measure11     time1  28.8
12  measure1     time2   8.7
13  measure2     time2   2.5
14  measure3     time2   2.7
15  measure4     time2   6.5
16  measure5     time2   8.3
17  measure6     time2   7.9
18  measure7     time2   6.5
19  measure8     time2   8.8
20  measure9     time2  13.1
21 measure10     time2  13.7
22 measure11     time2  21.3
Mario
  • 2,393
  • 2
  • 17
  • 37