Graph a list result

I've the next data:

df<-structure(list(var_A_full = c(NA, -0.0093283290621926, -0.0107151992044624, 
-0.0021176543656507, 0.0085585976342454, 0.0030507108768911, 
0.0228451246114698, 0.0091612100176144, 0.0393169367500201, 0.169084952991692, 
-0.160121923287826, 0.024086856796707, -0.032284552010905, -0.013572411154769, 
-0.0418036709155245, -0.0049331530942368, -0.0125670119396756, 
-0.0112896088093455, -0.0092601182292072, 0.0044728759707422, 
-0.0028909768734262, 0.0334549789429705, 0.0463064780353561, 
-0.0105762283325573, -0.0296291492595214, -0.0132177256835618, 
-0.0024914626930884, -0.0185649442391584, 0.0032318810183712, 
0.000496453184548704, -0.0041063067031196, -0.0130130527853509, 
0.014557824998084, -0.0269541013202162, 0.00303411725795906, 
-0.0127178818797811, 0.00371911560732697, -0.000667241898482669, 
0.014349561528856, NA, NA, -0.96730079614975, -0.1526186780245, 
0.90950561575272, -0.75157829590424, 0.90807733386924, 3.70347207536389, 
0.0870217300134701, 2.4577260710873, 1.43646600808476, -0.3648868000191, 
-1.12534018984762, 2.68578043692102, -2.17463906880725, -0.58997506355173, 
1.13271555206898, 0.1438857915828, -2.44463103309497, -1.53772097299338, 
-0.16485632622617, -1.21257516095732, 3.31002246536938, -0.72798161092985, 
2.00608989650132, -1.37786964009866, -2.50550406459061, 1.38712461402377, 
-3.83155534439509, 0.17678971831511, 0.01947235564012, -0.68779017830383, 
-0.58809076968297, 0.20517998292474, -0.15689595057627, -0.28738362358016, 
0.32742336606266, -0.3925174477257, 0.51396247843507, -0.7551762650333, 
NA, NA, 0.0533142174434064, -0.0234023762839068, -0.0107494256272873, 
0.0221479741611685, -0.0376340576915577, 0.0174138123570929, 
0.0459098890615668, -0.034613940419993, -0.0171515922644891, 
-0.0130367318877081, -0.0054986623944401, -0.0932208338539748, 
0.106182497262645, 0.0021397363372424, -0.013503617499049, -0.0037250744303149, 
-0.0042780239798658, 0.0046931561514516, -0.0061530737120735), 
    sh_A = c(NA, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 
    1L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 
    0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, NA, NA, 0L, 
    0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 
    1L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 1L, 0L, 0L, 0L, 0L, 
    0L, 0L, 0L, 0L, 0L, 0L, 0L, NA, NA, 0L, 1L, 0L, 0L, 1L, 0L, 
    0L, 1L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L)), row.names = c(NA, 
100L), class = "data.frame")

And, i executed the following code to calculate the percentiles 25,50,75 by groups (Normal or Shocks)

by(df$var_A_full,
   INDICES = factor(df$sh_A,labels = c("Normal","Shocks")),
   quantile,probs = c(0.25,0.5,0.75))

I need to graph the result like the following image

Screenshot (13)
Any ideas ?

Starting with your code and data, it just takes a few steps to make a flipped bar chart. I do not know how to make a 3D bar chart and I believe that is discouraged.

set.seed(1)
DF <-structure(list(var_A_full = c(NA, -0.0093283290621926, -0.0107151992044624, 
                                       -0.0021176543656507, 0.0085585976342454, 0.0030507108768911, 
                                       0.0228451246114698, 0.0091612100176144, 0.0393169367500201, 0.169084952991692, 
                                       -0.160121923287826, 0.024086856796707, -0.032284552010905, -0.013572411154769, 
                                       -0.0418036709155245, -0.0049331530942368, -0.0125670119396756, 
                                       -0.0112896088093455, -0.0092601182292072, 0.0044728759707422, 
                                       -0.0028909768734262, 0.0334549789429705, 0.0463064780353561, 
                                       -0.0105762283325573, -0.0296291492595214, -0.0132177256835618, 
                                       -0.0024914626930884, -0.0185649442391584, 0.0032318810183712, 
                                       0.000496453184548704, -0.0041063067031196, -0.0130130527853509, 
                                       0.014557824998084, -0.0269541013202162, 0.00303411725795906, 
                                       -0.0127178818797811, 0.00371911560732697, -0.000667241898482669, 
                                       0.014349561528856, NA, NA, -0.96730079614975, -0.1526186780245, 
                                       0.90950561575272, -0.75157829590424, 0.90807733386924, 3.70347207536389, 
                                       0.0870217300134701, 2.4577260710873, 1.43646600808476, -0.3648868000191, 
                                       -1.12534018984762, 2.68578043692102, -2.17463906880725, -0.58997506355173, 
                                       1.13271555206898, 0.1438857915828, -2.44463103309497, -1.53772097299338, 
                                       -0.16485632622617, -1.21257516095732, 3.31002246536938, -0.72798161092985, 
                                       2.00608989650132, -1.37786964009866, -2.50550406459061, 1.38712461402377, 
                                       -3.83155534439509, 0.17678971831511, 0.01947235564012, -0.68779017830383, 
                                       -0.58809076968297, 0.20517998292474, -0.15689595057627, -0.28738362358016, 
                                       0.32742336606266, -0.3925174477257, 0.51396247843507, -0.7551762650333, 
                                       NA, NA, 0.0533142174434064, -0.0234023762839068, -0.0107494256272873, 
                                       0.0221479741611685, -0.0376340576915577, 0.0174138123570929, 
                                       0.0459098890615668, -0.034613940419993, -0.0171515922644891, 
                                       -0.0130367318877081, -0.0054986623944401, -0.0932208338539748, 
                                       0.106182497262645, 0.0021397363372424, -0.013503617499049, -0.0037250744303149, 
                                       -0.0042780239798658, 0.0046931561514516, -0.0061530737120735), 
                        sh_A = c(NA, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 
                                 1L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 
                                 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, NA, NA, 0L, 
                                 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 
                                 1L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 1L, 0L, 0L, 0L, 0L, 
                                 0L, 0L, 0L, 0L, 0L, 0L, 0L, NA, NA, 0L, 1L, 0L, 0L, 1L, 0L, 
                                 0L, 1L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L)), row.names = c(NA, 
                                                                                                     100L), class = "data.frame")
ByResult <- by(DF$var_A_full,
   INDICES = factor(DF$sh_A,labels = c("Normal","Shocks")),
   quantile,probs = c(0.25,0.5,0.75))

DFresult <- data.frame(Group=names(unlist(ByResult)),Value=unlist(ByResult))
library(tidyr)
library(ggplot2)
DFresult <- separate(DFresult,col = Group,into = c("Group","Quant"), sep = "\\.")
ggplot(DFresult,aes(x=Group,y=Value, fill=Quant)) + geom_col(position="dodge") + 
  coord_flip()

Created on 2020-10-30 by the reprex package (v0.3.0)

1 Like

Is the solution. Thank you.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.