I have a dataset which looks like this one below.
month Yi Yi+1
1 0.014310185 13.43838262
2 0.014310185 15.7792948
3 0.176113783 16.14479846
4 3.143663699 16.54060078
5 3.755478277 16.75810501
6 3.767263653 17.03156884
7 3.767263653 17.03156884
8 3.829219647 17.03156884
9 4.375269901 17.78482322
10 8.707536696 18.47995179
11 10.28741362 21.33942187
12 10.66218286 21.82637774
I have 15 columns of Y (Yi to Yi+14). Column Yi, for instance, corresponds to the volume of precipitation over the 12 months of the year Yi. I have to barplot the volume of precipitation of all years (with their months) side by side on the x axis. In the end, I have to get something like this:
![enter image description here][1]
I have already tried the melt
and group_by
functions to reshape my data frame following this commands:
df <- read_excel("df.xls", col_names = FALSE, skip = 1)
colnames(df) <- c("month", "Yi", paste0("Yi+", 1:14)
df.melt <- melt(tab.df, id = c("month", "Yi", paste0("Yi+", 1:14))
bar <- group_by(df.melt, aes(x = 1:length(value), y = value, fill=factor(month))) +
geom_bar(position="dodge", stat="identity"))
ggplot(bar, aes(x=variable, y=mean, fill=factor(month)))
but it did not work. any suggestions how to do that?