kindly guide me on how i can plot the following data on the same graph using the kernel density. i will like to use as to compare performance mu1<-c(500.0035, 501.2213, 500.7532, 500.2622, 500.3391, 500.1618, 499.9511, 500.1843, 499.8945, 499.8467) mu2<-c(498.9623, 504.7938, 506.8957, 495.6634, 506.2751, 503.4344, 503.9103, 512.3021,492.3065, 500.8908) mu3<-c(498.9352, 501.3470, 506.7885, 497.3446, 505.6911, 500.0000, 503.9103, 512.0994,492.3065, 500.0001) mu4<-c(498.5626, 501.3469, 506.7781, 497.3466, 505.6723, 500.0000, 503.9103, 512.0936,492.3065, 500.0000) thanks [[alternative HTML version deleted]]
You can do it, but mu1 has a much smaller variance and mu3 and mu4 are almost identical so they overplot.> xy1 <- density(mu1) > xy2 <- density(mu2) > xy3 <- density(mu3) > xy4 <- density(mu4) > Density <- cbind(xy1$y, xy2$y, xy3$y, xy4$y) > x <- cbind(xy1$x, xy2$x, xy3$x, xy4$x) > matplot(x, Density, type="l") > legend("topright", c("mu1", "mu2", "mu3", "mu4"), col=1:4, lty=1:4)------------------------------------- David L Carlson Department of Anthropology Texas A&M University College Station, TX 77840-4352 -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of IZHAK shabsogh Sent: Thursday, June 26, 2014 1:47 AM To: r-help at r-project.org Subject: [R] graph kindly guide me on how i can plot the following data on the same graph using the kernel density. i will like to use as to compare performance mu1<-c(500.0035, 501.2213, 500.7532, 500.2622, 500.3391, 500.1618, 499.9511, 500.1843, 499.8945, 499.8467) mu2<-c(498.9623, 504.7938, 506.8957, 495.6634, 506.2751, 503.4344, 503.9103, 512.3021,492.3065, 500.8908) mu3<-c(498.9352, 501.3470, 506.7885, 497.3446, 505.6911, 500.0000, 503.9103, 512.0994,492.3065, 500.0001) mu4<-c(498.5626, 501.3469, 506.7781, 497.3466, 505.6723, 500.0000, 503.9103, 512.0936,492.3065, 500.0000) ? thanks [[alternative HTML version deleted]]
Does this do what you want? d1 <- density(mu1) d2 <- density(mu2) d3 <- density(mu3) d4 <- density(mu4) matplot( cbind( d1$x, d2$x, d3$x, d4$x ), cbind( d1$y, d2$y, d3$y, d4$y ), type='l') Or in a more expandable way: mus <- mget( ls(pat='^mu') ) ds <- lapply( mus, density ) xs <- sapply( ds, `[[`, "x" ) ys <- sapply( ds, `[[`, "y" ) matplot(xs,ys, type='l') You could also combine the data into a single data frame and use lattice or ggplot2 tools to create a similar graph. If not, then please give more details on what you want, what the graph should look like, what you have tried and how it differs from what you want. On Thu, Jun 26, 2014 at 12:47 AM, IZHAK shabsogh <ishaqbaba at yahoo.com> wrote:> kindly guide me on how i can plot the following data on the same graph using the kernel density. i will like to use as to compare performance > > mu1<-c(500.0035, 501.2213, 500.7532, 500.2622, 500.3391, 500.1618, 499.9511, 500.1843, 499.8945, 499.8467) > mu2<-c(498.9623, 504.7938, 506.8957, 495.6634, 506.2751, 503.4344, 503.9103, 512.3021,492.3065, 500.8908) > mu3<-c(498.9352, 501.3470, 506.7885, 497.3446, 505.6911, 500.0000, 503.9103, 512.0994,492.3065, 500.0001) > mu4<-c(498.5626, 501.3469, 506.7781, 497.3466, 505.6723, 500.0000, 503.9103, 512.0936,492.3065, 500.0000) > > > thanks > [[alternative HTML version deleted]] > > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Gregory (Greg) L. Snow Ph.D. 538280 at gmail.com
As Greg has listed lattice Here are ways in lattice quick 1 panel library(lattice) densityplot(~ mu1+mu2+mu3+mu4) dat = data.frame(mu = c(mu1,mu2,mu3,mu4), gp = rep(1:4, sapply(list(mu1,mu2,mu3,mu4), length)) ) densityplot(~ mu|gp, data = dat) densityplot(~ mu|gp, dat, pch = "|") see ?xyplot ?panel.densityplot Duncan Duncan Mackay Department of Agronomy and Soil Science University of New England Armidale NSW 2351 Email: home: mackay at northnet.com.au -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of IZHAK shabsogh Sent: Thursday, 26 June 2014 16:47 To: r-help at r-project.org Subject: [R] graph kindly guide me on how i can plot the following data on the same graph using the kernel density. i will like to use as to compare performance mu1<-c(500.0035, 501.2213, 500.7532, 500.2622, 500.3391, 500.1618, 499.9511, 500.1843, 499.8945, 499.8467) mu2<-c(498.9623, 504.7938, 506.8957, 495.6634, 506.2751, 503.4344, 503.9103, 512.3021,492.3065, 500.8908) mu3<-c(498.9352, 501.3470, 506.7885, 497.3446, 505.6911, 500.0000, 503.9103, 512.0994,492.3065, 500.0001) mu4<-c(498.5626, 501.3469, 506.7781, 497.3466, 505.6723, 500.0000, 503.9103, 512.0936,492.3065, 500.0000) thanks [[alternative HTML version deleted]]