0

I am currently trying to analyze different strategies for a processing method. There are 4 quantities of 2 options (2^4) and 1 quantity of 4 options (4) for a total of 64 different rows of the dataframe. For example, the data frame would be structured as follows:

Overall_Name | option1 | option2 | option3  | option 4 | option5 | value

Where each object is a 3 character string corresponding to the option.

I would like to be able to compare based on an option, so for example, if I'm testing to compare option1, I would like the other 4 options to form the x axis (something like option2.option3.option4.option5) and the y axis be the value, thereby, the strategies that differ only in the option1 would appear at the same x position, but presumably different y position (and then compare both choices with some statistical metric that I haven't decided upon yet, but that's a bit farther down the line).

So, for example, if I had:

Overall_Name              | option1 | option2 | option3  | option 4 | option5 | value
data.aaa.aaa.aaa.aaa.aaa    aaa       aaa       aaa        aaa        aaa       .93
data.bbb.aaa.aaa.aaa.aaa    bbb       aaa       aaa        aaa        aaa       .85

I would want the aaa.aaa.aaa.aaa position of the x axis to have one point (colored a) to show .93, and the other (colored b) to show .85.

Simplified example code:

  dataset <- data.frame(matrix(ncol=5, nrow=0))
  names(dataset) <- c("name", "opt1","opt2","opt3", "mnr")
  name <- "name1"
  opt1 <- "aaa"
  opt2 <- "aaa"
  opt3 <- "aaa"
  val <- .95
  dataset <- rbind(dataset, data.frame(name, opt1, opt2, opt3, val))
  name <- "name1"
  opt1 <- "bbb"
  opt2 <- "aaa"
  opt3 <- "aaa"
  val <- .85
  dataset <- rbind(dataset, data.frame(name, opt1, opt2, opt3, val))
  name <- "name1"
  opt1 <- "aaa"
  opt2 <- "bbb"
  opt3 <- "aaa"
  val <- .97
  dataset <- rbind(dataset, data.frame(name, opt1, opt2, opt3, val))
  name <- "name1"
  opt1 <- "bbb"
  opt2 <- "bbb"
  opt3 <- "aaa"
  val <- .87
  dataset <- rbind(dataset, data.frame(name, opt1, opt2, opt3, val))

then some command would produce two lines, both from "aaa.aaa" to "bbb.aaa", one with values [.95, .97] and the other with values [.85, .87], and the first line would be called "aaa" and the second "bbb".

Jaap
  • 81,064
  • 34
  • 182
  • 193
Eric
  • 946
  • 2
  • 12
  • 25
  • 1
    Have you looked at `?dotchart`. For example, `with(data, dotchart(value, labels=option1))`. A reproducible example would be helpful http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – Whitebeard Sep 26 '15 at 21:03
  • does that make more sense? – Eric Sep 26 '15 at 22:28

1 Answers1

1

Have you looked at faceting? Maybe this will spark some ideas.

# for a plot of opt2, create an interaction of opt1 and opt3
dat <- dataset
dat$opt1.opt3 <- with(dat, interaction(opt1, opt3))

The panel on the left is for opt2 = aaa, and the panel on the right is for opt2 = bbb. Each tick on the x-axis is for a unique opt1.opt3 combination. The color represents the opt1.opt3 as well.

p <- ggplot(dat, aes(x = opt1.opt3, y = val, color = opt1.opt3)) +
     geom_point() + facet_wrap(~ opt2)
p

enter image description here

Whitebeard
  • 5,945
  • 5
  • 24
  • 31
  • Yea; that's one thing that I found, however I wanted the x axis to be not the parameter being compared but the ones held "constant" if that makes sense – Eric Sep 27 '15 at 21:27
  • so that, let's say I had a total of 4 things (binarized, so it's a yes or no whether they are on/off) and i want to compare option 2 on vs option 2 off. so I would want the x axis to specify option1.option3.option4, so that each tick on the axis represents each individual strategy, and then option 2 on would be say a blue line, and option 2 off would be a red line. that way, you might be able to say, "oh look, all else equal (this being why the x axis would need to be option1.option3.option4), option2 on kicks the pants off of option2 off" or vice versa. – Eric Sep 27 '15 at 21:29
  • I was thinking something like, "ggplot() + geom_line(data=(melted_dataset$option2=="bbb") ... rest of the command...) + geom_line(data=(melted_dataset$option2=="aaa") ... rest of the command...) but had no luck after two hours of playing around :( – Eric Sep 27 '15 at 21:35
  • Not sure that this is exactly what you are looking for, but it might give you some ideas. Sorry I can't visualize what you are describing better. Like you said, I am sure there is a straightforward solution. – Whitebeard Sep 27 '15 at 23:42
  • Yea it's hard to know exactly what someone wants from a description; Imma give it a go tomorrow some more and play around with that. looks like it might be possible with that method. Thanks for your assistance! – Eric Sep 28 '15 at 00:26