Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201945

How to generate a grouped bar chart with 2 categorical variables

$
0
0

I would like to generate a bar chart similar to the one shown below. I would like to use rhoas x-axis and power as y-axis. And I have 2 categorical variables m and c. How can I generate a grouped bar with 2 grouping variables?

Any other idea of visualizing will be welcomed.

In this picture they use m as color, rho and c as x axis variables.

different color: m

> dput(ds2)
structure(list(X = c(105L, 135L, 141L, 165L, 171L, 177L, 201L, 
207L, 213L, 231L, 237L, 243L, 249L, 267L, 273L, 279L, 285L, 303L, 
309L, 315L, 321L, 465L, 495L, 501L, 525L, 531L, 537L, 561L, 567L, 
573L, 591L, 597L, 603L, 609L, 627L, 633L, 639L, 645L, 861L, 891L, 
897L, 921L, 927L, 933L, 957L, 963L, 969L, 1287L, 1293L), d_s = c(0.2, 
0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 
0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 
0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 
0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2), m = structure(c(6L, 
5L, 6L, 4L, 5L, 6L, 4L, 5L, 6L, 3L, 4L, 5L, 6L, 3L, 4L, 5L, 6L, 
3L, 4L, 5L, 6L, 6L, 5L, 6L, 4L, 5L, 6L, 4L, 5L, 6L, 3L, 4L, 5L, 
6L, 3L, 4L, 5L, 6L, 6L, 5L, 6L, 4L, 5L, 6L, 4L, 5L, 6L, 5L, 6L
), .Label = c("5", "10", "15", "20", "25", "30"), class = "factor"), 
    c = structure(c(3L, 4L, 4L, 5L, 5L, 5L, 6L, 6L, 6L, 7L, 7L, 
    7L, 7L, 8L, 8L, 8L, 8L, 9L, 9L, 9L, 9L, 4L, 5L, 5L, 6L, 6L, 
    6L, 7L, 7L, 7L, 8L, 8L, 8L, 8L, 9L, 9L, 9L, 9L, 6L, 7L, 7L, 
    8L, 8L, 8L, 9L, 9L, 9L, 9L, 9L), .Label = c("4", "6", "8", 
    "10", "12", "14", "16", "18", "20"), class = "factor"), rho = c(0, 
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
    0, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 
    0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.03, 0.03, 
    0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.05, 0.05), n0 = c(1984L, 
    1491L, 748L, 1984L, 748L, 529L, 910L, 552L, 437L, 1984L, 
    647L, 461L, 387L, 1035L, 529L, 409L, 355L, 748L, 461L, 375L, 
    333L, 3055L, 2018L, 952L, 2647L, 916L, 638L, 1094L, 650L, 
    512L, 2464L, 751L, 530L, 443L, 1202L, 601L, 462L, 401L, 12390L, 
    4206L, 1528L, 5721L, 1370L, 909L, 1602L, 890L, 686L, 25498L, 
    2685L), results = c(TRUE, TRUE, FALSE, TRUE, TRUE, TRUE, 
    TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, TRUE, FALSE, 
    TRUE, FALSE, TRUE, FALSE, TRUE, TRUE, TRUE, FALSE, FALSE, 
    FALSE, FALSE, TRUE, TRUE, TRUE, FALSE, FALSE, TRUE, TRUE, 
    TRUE, FALSE, TRUE, FALSE, TRUE, FALSE, FALSE, TRUE, FALSE, 
    FALSE, TRUE, TRUE, FALSE, FALSE, FALSE, TRUE), power = c(0.85, 
    0.87, 0.92, 0.89, 0.89, 0.89, 0.85, 0.89, 0.87, 0.89, 0.94, 
    0.9, 0.92, 0.88, 0.93, 0.88, 0.92, 0.88, 0.9, 0.86, 0.85, 
    0.88, 0.9, 0.95, 0.94, 0.9, 0.87, 0.84, 0.89, 0.93, 0.91, 
    0.86, 0.87, 0.87, 0.91, 0.88, 0.91, 0.89, 0.95, 0.9, 0.89, 
    0.95, 0.95, 0.87, 0.85, 0.9, 0.91, 0.91, 0.87)), row.names = c(37L, 
51L, 55L, 67L, 71L, 75L, 87L, 91L, 95L, 104L, 108L, 112L, 116L, 
125L, 129L, 133L, 137L, 147L, 151L, 155L, 159L, 211L, 226L, 230L, 
242L, 246L, 250L, 262L, 266L, 270L, 279L, 283L, 287L, 291L, 301L, 
305L, 309L, 313L, 390L, 405L, 409L, 421L, 425L, 429L, 441L, 445L, 
449L, 563L, 567L), class = "data.frame")

Viewing all articles
Browse latest Browse all 201945

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>