Home > Software design >  trouble with plot R Grouped bar chart bivariate
trouble with plot R Grouped bar chart bivariate

Time:01-18

I'm trying to plot bivariate grouped bar chart but it seems i have issue because of my values but i can't understand why.. Here are my data

> data
      dijarn   MIR4299   MIR8070   SNORD97 ZBED5.AS1
1  dijarn043 0.0000000 0.0000000  194.9916  341.2352
2  dijarn044 0.0000000 0.0000000  118.8450  235.6757
3  dijarn045 0.0000000 3.7225624  251.8934  260.5794
4  dijarn046 0.0000000 1.0262261 1838.9972  250.3992
5  dijarn047 0.0000000 0.9395318  316.6222  257.4317
6  dijarn048 0.0000000 0.0000000  205.4994  177.0655
7  dijarn049 0.0000000 0.0000000 1329.5549  230.5586
8  dijarn050 0.0000000 0.0000000  312.9863  274.6614
9  dijarn051 0.0000000 0.0000000  426.0749  266.8925
10 dijarn052 0.0000000 0.7875521  229.1777  232.3279
11 dijarn053 0.0000000 1.1187722  465.4092  193.5476
12 dijarn054 0.0000000 0.0000000  831.1748  180.4236
13 dijarn055 0.0000000 0.0000000 1192.6965  203.9787
14 dijarn056 0.0000000 0.0000000  475.9401  234.3250
15 dijarn057 0.0000000 0.0000000  491.1088  196.4435
16 dijarn058 0.0000000 0.0000000 1884.6339  232.4619
17 dijarn059 0.0000000 0.0000000  292.7574  222.4956
18 dijarn060 0.0000000 2.6733694  427.7391  200.5027
19 dijarn061 0.0000000 1.0432994 1179.9717  205.5300
20 dijarn062 2.5700452 0.0000000 1473.4926  203.8903
21 dijarn063 0.0000000 0.0000000 2584.8096  262.0357
22 dijarn064 0.0000000 0.0000000  306.2727  237.2535
23 dijarn068 0.0000000 0.0000000  251.8642  301.0377
24 dijarn072 0.0000000 2.5243193  350.0389  228.8716
25 dijarn073 0.0000000 0.0000000  607.1432  157.2067
26 dijarn074 0.0000000 0.0000000  288.7701  225.4517
27 dijarn075 0.0000000 0.0000000  738.1456  148.7173
28 dijarn076 0.0000000 0.8897780  249.1378  187.7432
29 dijarn077 0.9168659 0.0000000  305.3163  141.1973
30 dijarn078 4.8479593 0.0000000  142.2068  231.0861
31 dijarn080 0.0000000 1.1491231  574.5615  314.8597
32 dijarn081 0.0000000 0.0000000  407.1133  181.4562
33 dijarn083 0.0000000 1.3098216  174.2063  242.3170
34 dijarn084 2.1523298 0.0000000  120.5305  217.3853
35 dijarn085 0.0000000 0.0000000  335.5659  188.3745
36 dijarn086 0.0000000 0.0000000  172.4283  256.1383
37 dijarn087 0.0000000 0.0000000  201.0911  229.6776

then i'm reorganized my data with function melt

    data.m <- melt(data, id.var = "dijarn")
    > data.m
           dijarn  variable        value
    1   dijarn043   MIR4299    0.0000000
    2   dijarn044   MIR4299    0.0000000
    3   dijarn045   MIR4299    0.0000000
    4   dijarn046   MIR4299    0.0000000
    5   dijarn047   MIR4299    0.0000000
    6   dijarn048   MIR4299    0.0000000
    7   dijarn049   MIR4299    0.0000000
...

and then to plot :

ggplot(data.m, aes(x = dijarn,fill = variable))   geom_bar(position = position_dodge(preserve = "single"))

enter image description here

i can't understand why all the barplot seems to have all the same length, value seems to be correct ? thanks for your help!

CodePudding user response:

Something like this?

df %>% 
  pivot_longer(-dijarn) %>%  
  ggplot()   
  aes(x = as_factor(parse_number(dijarn)), y = value, fill = name)   
  geom_col(position = "dodge")  
  theme_light()   coord_flip()   xlab("Dijarn")   ylab("Value")

enter image description here

  • Related