Entering edit mode
7.9 years ago
Lila M
★
1.3k
Hi everybody,
I want to smooth 3 different samples and see the result in the same plot. For that propose I'm using ggplot. I can plot the 3 curves in the same plot , but when I've tried to smoothing them, I have to make it separately, as follow:
c <- ggplot(d3, aes(x = bins, y = sample1, color="sample1")) + labs(y = "Coverage", x = "distance to TSS")
d <- ggplot(d3, aes(x = bins, y =sample2, color="sample2"))+ labs(y = "Coverage", x = "distance to TSS")
e <- ggplot(d3, aes(x = bins, y = sample3, color="sample3"))+ labs(y = "Coverage", x = "distance to TSS")
c + stat_smooth(span = 0.2)
d + stat_smooth(span = 0.2)
e + stat_smooth(span = 0.2)
Is there any way to plot the 3 smooth samples in the same plot?
Thank you very much
Now I have a data frame like this:
Are you suggesting me to perform a data frame like:
.....
Thanks!
Yes, then you can use either
stat_smooth()
orgeom_smooth()
(they're essentially the same thing) withaes(color=Samples, fill=Samples)
. ggplot works best with "tidy data" (google "R tidy data" if you're not familiar with that concept).Thank you Davon, I know hot to plot them after tidy my data, the problem is, that I don't know how to tidy it. Is the first time that I come across with this problem. Any suggestion for my starting?
Thanks!
Take a look at the tidyr package. In the vignette you have a nice introduction.
Thank you, I've used gather and arrange functions and now it works perfectly!!!!! thank you very much for your advice!
If you're just trying to add a smoothed series to the plot, have a look at the
geom_smooth()
aesthetic.I have a look, but I didn't find anything useful...