I have the following data set called t:
n <- 12
t <- data.frame(
V1 = runif(n, 0.12, 0.35),
V2 = runif(n, 0.25, 0.39),
group = gl(3, 4, labels = c("a1", "a2", "a3")),
x = seq_len(n),
color = rep(rep.int(c("R", "G"), 2), c(3, 4, 3, 2))
)
I created the following plot from this data.
p <- ggplot(t, aes(x, colour = color)) +
geom_point(aes(y = V1, size = 10)) +
geom_point(aes(y = V2, size = 10))
What I want to do now is to connect the points depending on the group column (e.g, points of group a1 will be connected with a blue line, points of group a2 will be connected in a yellow line, …) and i want the line to be different depending on V1 and V2 (dashed line for V1 and normal line for V2).
How this can be done?
First of all: naming a dataset “t” is not a good idea because it is confusing since there is a function t() as well.
The easiest way is to melt() your dataset first
Have a look at the ggplot2 website on how to customise the colours.