Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have some data which looks like:

sample  diff    chromosome  haploid coverage
B   90.9963099631   7   b   0.513
A   91.7019475021   12  a   8.234
C   90.3855783676   14  a   6.211
D   91.3407821229   17  b   4.321
E   91.5740740741   11  b   0.213
F   90.9963099631   7   b   0.513
G   91.7019475021   12  a   8.234
H   90.3855783676   14  a   6.211
I   91.3407821229   17  b   4.321
J   91.5740740741   11  b   0.213

And I want to visualise the change for 'diff' for different coverage value, across different chromosomes, so I did this:

plot = ggplot(dat, aes(x = coverage, y = diff, group  = chromosome, colour = chromosome, ylim(0, 100)) ) + geom_point(colour = chromosome) + stat_smooth(se=FALSE) + ylim(0, 100)

`geom_smooth()` using method = 'loess'

Now I think this isn't the best way to draw mutliple trendlines, but I produced this:

enter image description here

Which is kind of what I'm after. But I think in reality, all the curves shouldn't be exactly the same shape given my data, but the shape of all of them is basically identical. So has geom_smooth() plot a single LOWESS curve for all categories and then just shifted the same curve up and down for different categories?

If so, is there a way to make it plot independent lines for each category?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
421 views
Welcome To Ask or Share your Answers For Others

1 Answer

Cannot replicate your plot with the code you have provided. However, the correct syntax to obtain what you're looking for is the following, using the mtcars dataset.

library(ggplot2)

df = mtcars

df$cyl = factor(df$cyl)

ggplot(df, aes(x = mpg, y = disp, colour = cyl, group = cyl)) + 
  geom_point() + 
  geom_smooth(se=F)

Try to adjust your example / dataset on this code.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...