I have a data frame that looks like this
head(data1, 30)
date cur.gas
1 2015-01-01 00:00:45 RD
2 2015-01-01 00:02:45 RD
3 2015-01-01 00:04:45 RD
4 2015-01-01 00:06:45 RD
5 2015-01-01 00:08:45 RD
6 2015-01-01 00:10:45 RD
7 2015-01-01 00:12:45 RD
8 2015-01-01 00:14:45 RD
9 2015-01-01 00:16:45 RD
10 2015-01-01 00:18:45 RD
11 2015-01-01 00:20:45 RD
12 2015-01-01 00:22:45 RD
13 2015-01-01 00:24:45 RD
14 2015-01-01 00:26:45 RD
15 2015-01-01 00:28:45 RD
16 2015-01-01 00:30:45 RD
17 2015-01-01 00:40:45 BL
18 2015-01-01 00:42:45 BL
19 2015-01-01 00:44:45 BL
20 2015-01-01 00:46:45 BL
21 2015-01-01 00:48:45 BL
22 2015-01-01 00:50:45 BL
23 2015-01-01 00:52:45 BL
24 2015-01-01 00:54:45 BL
25 2015-01-01 00:56:45 BL
26 2015-01-01 00:58:45 BL
27 2015-01-01 01:00:45 BL
28 2015-01-01 01:46:45 RD
29 2015-01-01 01:50:45 RD
30 2015-01-01 01:52:45 RD
Where the cur.gas column indicated which line (Red (RD) or blue (BL)) is feeding the sample into the analyser. I want to create horizontal bar plot from this data that would show me the colour corresponding to the current line (red and blue).
I have tried using ggplot:
ggplot(data=data1, aes(x=0.1, y = date, col=cur.gas)) +
geom_bar(stat = "identity", width = 0.1) +
coord_flip() +
scale_fill_manual(values = c("red","blue")) +
theme(text = element_text(size = 10), axis.title = element_blank(), axis.text = element_blank(),
axis.ticks = element_blank())
And the output plot looks like this:
Which looks horible, and the colours are wrong (the legend gives red colour for BL and blue for RD).
Then I tried the barplot function:
attach(data1)
barplot(date,names.arg=cur.gas, horiz = TRUE, col = c("blue", "red"), legend = rownames(data1$cur.gas))
and I got this error:
Error in barplot.default(date, names.arg = cur.gas, horiz = TRUE, col = c("blue", :
'height' must be a vector or a matrix
I'm lost now. What should I do? Thanks a lot1