density-plot

How to overlay density plots in R?

匆匆过客 提交于 2019-11-26 18:19:46
I would like to overlay 2 density plots on the same device with R. How can I do that? I searched the web but I didnt find any obvious solution (I am rather new to R). My idea would be to read data from a text file (columns) and then use plot(density(MyData$Column1)) plot(density(MyData$Column2), add=T) well something in this spirit... Thanks in advance cbeleites use lines for the second one: plot(density(MyData$Column1)) lines(density(MyData$Column2)) make sure the limits of the first plot are suitable, though. ggplot2 is another graphics package that handles things like the range issue Gavin

Any suggestions for how I can plot mixEM type data using ggplot2

你。 提交于 2019-11-26 17:33:19
问题 I have a sample of 1m records obtained from my original data. (For your reference, you may use this dummy data that may generate approximately similar distribution b <- data.frame(matrix(rnorm(2000000, mean=c(8,17), sd=2))) c <- b[sample(nrow(b), 1000000), ] ) I believed the histogram to be a mixture of two log-normal distributions and I tried to fit the summed distributions using EM algorithm using the following code: install.packages("mixtools") lib(mixtools) #line below returns EM output