Re: [R] Counting question

From: Gabor Grothendieck <ggrothendieck_at_myway.com>
Date: Sat 31 Jul 2004 - 03:26:04 EST

Gabor Grothendieck <ggrothendieck <at> myway.com> writes:

:
: Adair, Laurence <Laurence.Adair <at> parsons.com> writes:
:
: > Here is something that sounds simple, but I'm having trouble getting it. I
: > have a data frame with two columns, the first is date and the second is
: > employee ID. I'd like to plot date on the horizontal axis, employee ID on
: > the vertical axis, and the number of times the employee appears for the
: > given date as a color. I've kluged something where I make a table
: > (table(date, id)) and add points to a plot by looping through the rownames
: > (employee ids) of the table. But certainly there is a better way of doing
: > this??
:
: In the example below the first three lines create a random test
: data frame with columns date and id.
:
: The fourth line calculates the counts using table, converts it back
: to a data frame (which has the effect of adding a Freq column) and
: removes any row with a Freq of 0.
:
: The last two lines load package gregmisc and then plot the data
: using balloonplot from that package.
:
: set.seed(1)
: r <- 100 + sample(5, 25, replace = TRUE)
: DF <- data.frame(date = structure(rev(r), class = "Date"), id = r)
:
: DF2 <- subset(as.data.frame(table(DF)),Freq > 0)
:
: require(gregmisc)
: with(DF2, balloonplot(date, id, Freq))

and if you still want the color on the plot too add the dotcolor= arg where the example uses colors of the rainbow:

with(DF2, balloonplot(date, id, Freq, dotcol = rainbow(max(Freq))[Freq]))



R-help@stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Sat Jul 31 03:43:35 2004

This archive was generated by hypermail 2.1.8 : Wed 03 Nov 2004 - 22:55:23 EST