Suppose the following data set is given:
df <- data.frame(x1 = seq(1,8,1),
x2 = c("G1","G2","G1","G2",
"G1","G2","G1","G2"))
I want to create a grouped plot, for example a grouped bar chart. But I want to use the order of the rows of the dataset for the plot, i.e. instead of combining all values of group 1 and group 2 and then plotting them, I want the bar plot to have a kind of alternating structure in which first the value of group 1 is displayed in red as specified in the dataset, then blue for group 2, then red again for group 1, and so on. Is this possible? I have added a picture of what I envision.


