-1

I have data that looks like this:

tc    td
3    400
3    430
4    200
4    240
5    120
3    470
...

and so on. I would like to generate a boxplot(using default plotters or ggplot2) that groups data by the variable in the first column (tc), such that there is one box for each, 3,4,5 and so on. Data might not be restricted to 3,4,5 and I would prefer not having a hardcoded solution that asks me to split by the number in tc and plot each one individually.

I haven't found much online that gives me good examples (either the examples are hardcoded, or don't show how to split, or the example data is not immediately present, and I don't know whether that example fits my needs)

orderof1
  • 11,831
  • 4
  • 18
  • 18
  • 2
    When I look at the sidebar of your question I see plenty of links that should show you how to do this. That makes me think you haven't looked very hard... Can you explain a bit about what you have tried, where you've looked and why it hasn't helped? – Justin May 29 '13 at 21:40

1 Answers1

0

Without a sample dataset, I would try this:

ggplot(df) + geom_boxplot(aes(x=tc, y=td))
harkmug
  • 2,725
  • 22
  • 26
  • I had tried this and got a plot like: http://postimg.org/image/kd0uwje7b/ I also made $tc as factor, but that didn't help. I get a graph like http://postimg.org/image/cj09b56ef/ – orderof1 May 29 '13 at 22:00
  • It appears to be an issue of your data.frame format. `melt` helps resolve some of this, but it would be a lot easier if you could post some data: http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – harkmug May 29 '13 at 22:10
  • And this works, but the y coordinates are mungled up: ggplot(data = toPlot2,aes(x=factor(toPlot2$tc), y=toPlot2$td)) + geom_boxplot(aes(group=toPlot2$tc)) gives http://postimg.org/image/t25ywp7q1/ – orderof1 May 29 '13 at 22:12