Skip to content
Prev 75204 / 398502 Next

use different symbols for frequency in a plot

On Mon, 2005-08-08 at 11:57 -0700, Kerry Bush wrote:
You might want to review this recent post by Deepayan Sarkar:

https://stat.ethz.ch/pipermail/r-help/2005-July/074042.html

with modest modification you can replace his example, which plots the
frequencies with:

x <- c(rep(.1,5),rep(.2,6),rep(.4,10),rep(.5,20))
y <- c(rep(.5,3),rep(.6,8),rep(1.2,8),rep(2.5,18),rep(3,4))

temp <- data.frame(x, y)

foo <- subset(as.data.frame(table(temp)), Freq > 0)
x   y Freq
1  0.1 0.5    3
5  0.1 0.6    2
6  0.2 0.6    6
11 0.4 1.2    8
15 0.4 2.5    2
16 0.5 2.5   16
20 0.5   3    4

# Use cut() to create the bins and specify the plotting symbols
# for each bin, which are the 'label' values
foo$sym <- with(foo, cut(Freq, c(0, 5, 10, Inf), 
                         labels = c(21, 22, 24))) 


# convert 'foo' to all numeric from factors above for plotting
foo <- apply(foo, 2, function(x) as.numeric(as.character(x)))
x   y Freq sym
1  0.1 0.5    3  21
5  0.1 0.6    2  21
6  0.2 0.6    6  22
11 0.4 1.2    8  22
15 0.4 2.5    2  21
16 0.5 2.5   16  24
20 0.5   3    4  21


# Now do the plot. Keep in mind that 'foo' is now
# a matrix, rather than a data frame
plot(foo[, "x"], foo[, "y"], pch = foo[, "sym"])


HTH,

Marc Schwartz