Hi all,
I hoped someone could teach me how to make a plot with the following dataframe:
group season 1 season 2 season 3 season 4
bananas 1 4 5 7
apples 6 10 8 2
pears 3 5 10 4
What I want to create is a bargraph with on the x-axis all the yields of season 1 for bananas, apples and pears, so three columns. I want to do the same for season 2, 3 and 4, thus ending with a bar graph with four clusters of 3 bars, totalling to 12 bars. On the y axis the amount should be stated, so that the yields of different fruits per season can be compared. I also want to give the bars of one species the same color and indicate this in a legend. I have tried solving this myself using the melt function (which I did not get to work), the tidyverse gather function (also could not get it to work) and I also tried to use barplot (but this also did not work). An example of code I used, and which I intuitively felt like would probably be the easiest of my three tryouts to fix:
ggplot(mean_all %>% gather(S1, S2, S3, S4, -group),
aes(x=group,y = seasons, fill = S1, S2, S3, S4)) +
geom_bar(stat = 'identity', position = 'dodge')
seasons <- c(mean_all$S1,mean_all$S2,mean_all$S3,mean_all$S4)
However, I as a beginner in R just cannot seem to make it work...
I have searched and tried out many tutorials and examples without solving this, soI am really hoping someone here is willing to take a look and help me out.