Creating two dodged barplots stacked on top of each other for my two variables

Say that I have a data frame that looks like this...

#create dataframe
rG_activity <- c("0.368", "0.468", "0.427", "0.091")
rG_activity_error_intervals <- c("(0.468, 0.268)", "(0.568, 0.368)", "(0.527, 0.327)", "(1.091, -0.909)")
rG_task_persistence <- c("-0.462", "-0.345", "-0.291", "-1.062")
rG_task_persistence_error_intervals <- c("(-0.562, -0.362)", "(-0.445, -0.245)", "(-0.391, -0.191)", "(-2.091, -0.062)")
rE_activity <- c("-0.162", "-0.245", "-0.129", "-0.462")
rE_activity_error_intervals <- c("(-0.262, -0.062)", "(-0.345, -0.145)", "(-0.229, -0.029)", "(-0.562, -0.362)")
rE_task_persistence <- c("-0.362", "-0.245", "-0.191", "-0.162")
rE_task_persistence_error_intervals <- c("(-0.462, -0.262)", "(-0.345, -0.145)", "(-0.291, -0.091)", "(-0.262, -0.062)")
age <- c("30", "24", "18", "12")
df <- data.frame(age, rG_activity, rG_activity_error_intervals, rG_task_persistence, rG_task_persistence_error_intervals, rE_activity, rE_activity_error_intervals, rE_task_persistence, rE_task_persistence_error_intervals)

  age rG_activity rG_activity_error_intervals rG_task_persistence rG_task_persistence_error_intervals rE_activity rE_activity_error_intervals
1  30       0.368              (0.468, 0.268)              -0.462                    (-0.562, -0.362)      -0.162            (-0.262, -0.062)
2  24       0.468              (0.568, 0.368)              -0.345                    (-0.445, -0.245)      -0.245            (-0.345, -0.145)
3  18       0.427              (0.527, 0.327)              -0.291                    (-0.391, -0.191)      -0.129            (-0.229, -0.029)
4  12       0.091             (1.091, -0.909)              -1.062                    (-2.091, -0.062)      -0.462            (-0.562, -0.362)
  rE_task_persistence rE_task_persistence_error_intervals
1              -0.362                    (-0.462, -0.262)
2              -0.245                    (-0.345, -0.145)
3              -0.191                    (-0.291, -0.091)
4              -0.162                    (-0.262, -0.062)

The two main variables of interest are "activity" and "task_persistence". For instance, for activity, I have rG_activity and rE_activity for each age (12, 18, 24, 30), same for task_persistence, along with the respective error intervals for each age. I would like to create two dodged bar plots for "activity" and "task_persistence" stacked on top of each other just like my example below (which includes the error intervals and the legend at the bottom). (note: the values on the barplot below do not reflect the values in my sample data above). Would appreciate any help.

enter image description here



Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation