Data Frame

How can I make a Boxplot using the leftmost column as the Y axis, and each of the cells represent the frequency of each of X1, X2, etc... for the column header? Like this:


  • 1
    Two things, please: (1) Please do not post an image of code/data/errors: it cannot be copied or searched (SEO), it breaks screen-readers, and it may not fit well on some mobile devices. Ref: meta.stackoverflow.com/a/285557/3358272. (2) Wow that image is huge, makes reading the question for context a little difficult. Can you shrink that boxplot image a bit, please? (More #1 than #2, but still ... :-) – r2evans Nov 7 '18 at 22:21
  • 1
    (Also, please consider "accepting" answers for your previous questions.) – r2evans Nov 7 '18 at 22:24

I believe this is what you are looking for

d <- data.frame(c(0,5,17,32,13), c(9,11,20,14,13))
x <- -10
for (i in 1: length(d[,1])) {
  y <- rep(i, d[i,1])
  x <- c(x, y)
x <- x[-which(x == -10)]

enter image description here

  • Thank you, but how can I iterate through every column to have all the box plots for each column side by side? – Sid Jones Nov 7 '18 at 23:09
  • ggplot2 will be better for showing multiple plots on the same graph. to iterate through each column put the code in a for loop (aka x[j] where j is the column number) – Alexandra Thayer Nov 9 '18 at 16:36

Your Answer

