I have my dataframe as:
T_ID S1 S2
1 21 26
1 20 25
1 21 22
2 20 53
2 41 62
2 30 23
I have plotted the S1 and S2 in a same graph as per T_ID(T_ID "1" have one color, T_ID "2" have one color so on..). Now I want to plot the Standard deviation as per T_IDs in the same graph. I can't figure out how to do this..
The answer I am providing uses three packages:
tidyr
,dplyr
andggplot2
. It's a bit hacky, but I think it gives you the desired output but requires you to get the data into the right format and calculating your desired values to to define aesthetics prior to plotting it - a typical thing for ggplot2. If someone else has an easier way of doing this, I'd love to see it, right now this is the best I could come up with given the data provided.First, get your data into the right format (assuming your data is called "df"), calculate the mean and standard deviation per time point (T1, T2) and group (S1, S2), then plot the barplot with errorbars representing mean +/- SD.
Gives you the following
EDIT FOLLOWING OPS SPECIFICATIONS
First attempt that didn't work.
Second attempt.
EDIT - Possible solution to OPs question
Provides you with this plot below, where the errorbars are plotted according to longitude and lattitude. I gather with your real data the errorbars will be more aesthetically pleasing to the eye.