I need to plot three lines (onto a single graph) each of which represents one lab team\'s data (two variables / team). Ideally, the graph should look aesthetically pleasing (hen
The key thing is to organize your data before plotting so as to have a factor
column in the data frame indicating a separate line for each set of x
, y
values. For example:
set.seed(1)
df1 <- data.frame(e1 = sort(runif(5, 0.05, 0.25)),
e2 = sort(runif(5, 0.05, 0.25)),
e3 = sort(runif(5, 0.05, 0.25)),
t1 = sort(runif(5, 1, 100)),
t2 = sort(runif(5, 1, 100)),
t3 = sort(runif(5, 1, 100))
)
### reshape this to give a column indicating group
df2 <- with(df1,
as.data.frame(cbind( c(t1, t2, t3),
c(e1, e2, e3),
rep(seq(3), each=5) )
))
colnames(df2) <- c("temp","activity","team")
df2$team <- as.factor(df2$team)
Then
library(ggplot2)
ggplot(df2, aes(x=temp, y=activity, col=team)) + geom_line()
giving:
I'd do something like:
library(ggplot2)
ggplot(mtcars, aes(x = wt, y = mpg, color = as.factor(cyl))) + geom_line()
If you want more specific advice, I would suggest you expand your example, and include some example data, and provide more details regarding what the visualisation should tell.