Hi:
This sounds like your standard error bar plot. Here's one way to get it,
using lists, melt() from the reshape package and ggplot2.
# Generate 50 fake data sets with 200 rows and variables send, receive:
for(i in seq_len(50)) assign(paste('df', i, sep = ''),
data.frame(send = rnorm(200, 10, 5), receive = rnorm(200, 105, 10)))
# Generate a vector of data frame names
dnames <- paste('df', 1:50, sep = '')
# Create the function for processing one data frame. In this case, we
# want to melt the data first so that the variable names become factor
# levels and the data values are correspondingly stacked. We then use
# ddply() from package plyr to produce the mean and standard deviation
# from each variable.
f <- function(df) {
u <- melt(df)
ddply(u, .(variable), summarise, m = mean(value), s = sd(value))
}
# Slurp the data frames into a list and then add send and receive together
# This can probably be done without a loop using sapply, but the loop
# should be about as fast.
l <- vector('list', length(dnames))
for(i in seq_along(dnames)) {l[[i]] <- get(dnames[[i]])
l[[i]]$both = with(l[[i]], send + receive)}
# Now, apply the function f to each data frame in the list, and rbind the
# results together. Afterward, create dsn to distinguish the different
# data frames (I chose to use the numbers only as they can be used
# as the x-axis in the plots below.)
out <- do.call(rbind, lapply(l, f))
out$dsn <- rep(1:length(dnames), each = 3)
# Create the error bar plots for each of the 50 data frames by each
# variable, where the dot represents the mean and the ends of the
# segments represent a 1 SD distance from the mean.
p <- ggplot(out, aes(x = dsn, y = m, ymin = m - s, ymax = m + s))
p + geom_point(size = 2) + geom_errorbar(width = 0) +
facet_grid(variable ~ ., scales = 'free_y') +
xlab('Data set number')
Substitute your actual data frames for the fake ones (in particular,
redefine
dnames) and you should be good to go if you like the plot.
HTH,
Dennis
On Mon, Jul 5, 2010 at 9:08 AM, Ian Bentley <ian.bentley@gmail.com> wrote:
> Hello!
>
> I need to make a plot with whispers that does the following.
>
> Reads in 50 files, each file containing 200 data points. A file looks like
> this:
> base100.log
> Send Receive
> 10.5 100.3
> 15.0 102.4
> ...
>
> There are 100 lines, each with two data points. I need to read in the 50
> files, and plot three lines
>
> The first line is the mean of the send column with whiskers indicating
> standard deviation (Each file represents one data point)
>
> The second line is the mean of the receive column, as above.
>
> the final plot is the mean of the two summed, with whiskers as above.
>
> There will be 50 data points on the final graph, one for each file.
>
> I've done this sort of a thing before, but I really can't figure
out how to
> handle the different Columns.
>
> If I use read.table:
>
> x1 <- read.table("updateToSink1010.log")
>
> then x1 becomes a matrix, with two columns and 101 rows. -- including
> Send,
> Receive.
>
> Anyways, I'd appreciate a push in some direction - hopefully the right
one
> :).
>
> --
> Ian Bentley
> M.Sc. Candidate
> Queen's University
> Kingston, Ontario
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@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.
>
[[alternative HTML version deleted]]