How to make a graph of overclocking ggplot2 with multiple faces from the same number vector?

Suppose I have a data frame with records ( Value ) for 100 subjects ( Subject ), which were measured in three different ways ( Method ). Now I would like to build the Value for each method against each other, so in this case, "base-new", "base edge" and "new-edge". How can I do this in ggplot2 based on a single numeric variable using facet_wrap ?

 dummy <- data.frame(Value = c(rnorm(100, mean = 35, sd = 2), rnorm(100, mean = 47, sd = 2), rnorm(100, mean = 28, sd = 1)), Method = c(rep("base", times = 100), rep("new", times = 100), rep("edge", times = 100)), Subject = rep(paste0("M", seq_len(100)), times = 3)) str(dummy) ## 'data.frame': 300 obs. of 3 variables: ## $ Value : num 32.9 32.2 37 36.6 33 ... ## $ Method : Factor w/ 3 levels "base","edge",..: 1 1 1 1 1 1 1 1 1 1 ... ## $ Subject: Factor w/ 100 levels "M1","M10","M100",..: 1 13 24 35 46 57 68 79 90 2 ... 

This code does not work and is intended only to illustrate what I would like to do:

 library("ggplot2") ggplot(dummy, aes(Value)) + geom_point() + facet_wrap(~ Method) 

Edit

This would be my solution using base R :

 opar <- par() par(mfrow = c(1, 3)) plot(dummy[dummy$Method == "base", "Value"], dummy[dummy$Method == "new", "Value"], xlab = "base", ylab = "new") plot(dummy[dummy$Method == "base", "Value"], dummy[dummy$Method == "edge", "Value"], xlab = "base", ylab = "edge") plot(dummy[dummy$Method == "new", "Value"], dummy[dummy$Method == "edge", "Value"], xlab = "new", ylab = "edge") par(opar) 

Base r approach

+4
source share
1 answer

So, although this is not quite what you were looking for, it is approaching: I propose instead a graph matrix with facet_grid :

Your data needs a slightly different format:

 set.seed(1234) dummy <- data.frame(Value = c(rnorm(100, mean = 35, sd = 2), rnorm(100, mean = 47, sd = 2), rnorm(100, mean = 28, sd = 1)), Method = c(rep("base", times = 100), rep("new", times = 100), rep("edge", times = 100)), Subject = rep(paste0("M", seq_len(100)), times = 3)) dummy2 = rbind(cbind.data.frame(x = dummy$Value[1:100], xmet = rep("base", 100), y = dummy$Value[101:200], ymet = rep("new", 100)), cbind.data.frame(x = dummy$Value[1:100], xmet = rep("base", 100), y = dummy$Value[201:300], ymet = rep("edge", 100)), cbind.data.frame(x = dummy$Value[101:200], xmet = rep("new", 100), y = dummy$Value[201:300], ymet = rep("edge", 100))) 

And your plot is done with:

 library("ggplot2") ggplot(dummy2, aes(x = x, y = y)) + geom_point() + facet_grid(ymet ~ xmet) 

What gives:

enter image description here

Now you can add, for example. legend in the free field. My starting point was the answer to my question .

+1
source

All Articles