Plotting multiple lines per category

Hey guys,

Which parameter in ggplot lineplot can I use to create separate lines for the different replicates of a given group?
I'm sorry to bother you with this kind of miniscule question, but all I found by googling is how to create plots with multiple lines where they separate groups based on color, but in these examples there's always only one line per group. Is there another parameter which allows me to further group my data so that each replicate has its own line?

I suppose there is a column that designates the replicate. You can then make a new column that combines the group and the replicate and use that for the group argument of the plot. If you post some of your data, someone could make a more specific suggestion. To post data, you can use the dput() function. If your data are in a data frame named DF, run a command like

dput(head(DF, 25))

That will produce output that you can post here and others can use to replicate your data. I guessed that 25 lines of your data is enough to make a sample plot, Change that number to whatever works for your data. When you paste the output of dput() into a reply here, please put a line with three back ticks just before and after the output, like this:
```
pasted output goes here
```

Thanks for taking the time! I guess that is a solution as you describe it, but I actually didn't want to put them into separate groups, as they should just have the same color based on their group level. But probably they haven't built this into the function. I thought ggplot was quite flexible.

I find it very awkward to discuss R ggplots in pure theory. a little bit of data goes a long way towards finding a representation for that data.
How about a reprex ? dput is a good way as FJCC suggested.

A simple example.

library(ggplot2)
library(dplyr)

DF <- data.frame(Grp=c("A","A","A","A","B","B","B","B"),
                 Repl=c(1,1,2,2,1,1,2,2),
                 xValue=c(1,2,1,2,1,2,1,2),
                 yValue=c(1,2,1.5,2.2,1.25,2.3,0.5,3))
DF
#>   Grp Repl xValue yValue
#> 1   A    1      1   1.00
#> 2   A    1      2   2.00
#> 3   A    2      1   1.50
#> 4   A    2      2   2.20
#> 5   B    1      1   1.25
#> 6   B    1      2   2.30
#> 7   B    2      1   0.50
#> 8   B    2      2   3.00
DF <- DF |> mutate(GrpRepl=paste(Grp,Repl,sep = "_"))
ggplot(DF,aes(xValue,yValue,color=Grp,group=GrpRepl))+geom_line()                   

Created on 2022-06-21 by the reprex package (v2.0.1)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.