suppose I have the following data 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)) If I plot(x,y) in R, I will only get seven distinct points. What I want to do is to use different symbols to show the frequency at each point. e.g. if the frequncey is between 1 and 5, then I plot the point as a circle; if the frequency is between 6 and 10, then I plot the point as a square; if the frequency is above 10, then I plot the point as a triangle. I am not sure how to do this in R. Can anybody help me?
use different symbols for frequency in a plot
7 messages · Chuck Cleland, Adaikalavan Ramasamy, Kerry Bush +2 more
You might consider one of these approaches instead: plot(jitter(x), jitter(y)) or pdf(file="c:/AlphaExample.pdf", version = "1.4") plot(x, y, col = rgb(1, 0, 0, .2), pch = 16) dev.off()
Kerry Bush wrote:
suppose I have the following data 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)) If I plot(x,y) in R, I will only get seven distinct points. What I want to do is to use different symbols to show the frequency at each point. e.g. if the frequncey is between 1 and 5, then I plot the point as a circle; if the frequency is between 6 and 10, then I plot the point as a square; if the frequency is above 10, then I plot the point as a triangle. I am not sure how to do this in R. Can anybody help me?
______________________________________________ R-help at stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Chuck Cleland, Ph.D. NDRI, Inc. 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 452-1424 (M, W, F) fax: (917) 438-0894
Group by which variable ? If you mean the joint distribution of 'x' and
'y' then something along the following lines
x <- rep( c(0.1, 0.2, 0.4, 0.5), c(5, 6, 10, 20) )
y <- rep( c(0.5, 0.6, 1.2, 2.5, 3.0), c(3, 8, 8, 18, 4) )
new <- factor( paste(x, y, sep="_") )
tb <- table(new)
pchcode <- cut(tb , c(-Inf, 1, 5, 6, 10, Inf), labels=F)
tmp <- t( sapply( strsplit( names(tb), split="_") , c ) )
df <- data.frame( x=tmp[ ,1], y=tmp[ ,2],
freq=as.vector(tb), pchcode = pchcode -1 )
x y freq pchcode
1 0.1 0.5 3 1
2 0.1 0.6 2 1
3 0.2 0.6 6 2
4 0.4 1.2 8 3
5 0.4 2.5 2 1
6 0.5 2.5 16 4
7 0.5 3 4 1
And now to plot it, we use points() repeatedly.
plot( as.numeric(df$x), as.numeric(df$y), type="n" )
for( i in unique( df$pchcode ) ){
w <- which( df$pchcode == i )
points( df$x[w], df$y[w], pch=as.numeric(i) )
}
I am sure someone else will come up with a neater solution.
Can I also suggest that you try the following
plot( jitter(x), jitter(y) )
or better still the following
library(hexbin)
plot( hexbin(x, y) )
Regards, Adai
On Mon, 2005-08-08 at 11:57 -0700, Kerry Bush wrote:
suppose I have the following data 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)) If I plot(x,y) in R, I will only get seven distinct points. What I want to do is to use different symbols to show the frequency at each point. e.g. if the frequncey is between 1 and 5, then I plot the point as a circle; if the frequency is between 6 and 10, then I plot the point as a square; if the frequency is above 10, then I plot the point as a triangle. I am not sure how to do this in R. Can anybody help me?
______________________________________________ R-help at stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Thank you. But I only need three classes of freqnencies (in another words, only three kinds of symbols) for 1-5, 5-10 and above 10, not to use different symbols for different frequencies. Otherwise, clearly R will run out of available symbols and the plot is also hard to view. Thank you anyway. --- Adaikalavan Ramasamy <ramasamy at cancer.org.uk> wrote:
Group by which variable ? If you mean the joint
distribution of 'x' and
'y' then something along the following lines
x <- rep( c(0.1, 0.2, 0.4, 0.5), c(5, 6, 10,
20) )
y <- rep( c(0.5, 0.6, 1.2, 2.5, 3.0), c(3, 8, 8,
18, 4) )
new <- factor( paste(x, y, sep="_") )
tb <- table(new)
pchcode <- cut(tb , c(-Inf, 1, 5, 6, 10, Inf),
labels=F)
tmp <- t( sapply( strsplit( names(tb),
split="_") , c ) )
df <- data.frame( x=tmp[ ,1], y=tmp[ ,2],
freq=as.vector(tb), pchcode
= pchcode -1 )
x y freq pchcode
1 0.1 0.5 3 1
2 0.1 0.6 2 1
3 0.2 0.6 6 2
4 0.4 1.2 8 3
5 0.4 2.5 2 1
6 0.5 2.5 16 4
7 0.5 3 4 1
And now to plot it, we use points() repeatedly.
plot( as.numeric(df$x), as.numeric(df$y), type="n"
)
for( i in unique( df$pchcode ) ){
w <- which( df$pchcode == i )
points( df$x[w], df$y[w], pch=as.numeric(i) )
}
I am sure someone else will come up with a neater
solution.
Can I also suggest that you try the following
plot( jitter(x), jitter(y) )
or better still the following
library(hexbin)
plot( hexbin(x, y) )
Regards, Adai
On Mon, 2005-08-08 at 11:57 -0700, Kerry Bush wrote:
suppose I have the following data 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))
If I plot(x,y) in R, I will only get seven
distinct
points. What I want to do is to use different
symbols
to show the frequency at each point. e.g. if the frequncey is between 1 and 5, then I
plot
the point as a circle; if the frequency is between
6
and 10, then I plot the point as a square; if the frequency is above 10, then I plot the point as a triangle. I am not sure how to do this in R. Can anybody
help me?
______________________________________________ R-help at stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide!
On Mon, 2005-08-08 at 11:57 -0700, Kerry Bush wrote:
suppose I have the following data 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)) If I plot(x,y) in R, I will only get seven distinct points. What I want to do is to use different symbols to show the frequency at each point. e.g. if the frequncey is between 1 and 5, then I plot the point as a circle; if the frequency is between 6 and 10, then I plot the point as a square; if the frequency is above 10, then I plot the point as a triangle. I am not sure how to do this in R. Can anybody help me?
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)
foo
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)))
foo
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
Remove the '6' from the code that contains 'cut'. I am not sure how it
crept into my code. Then you should have the following mapping
Freq pch code
1-5 1
6-10 2
11- 3
I am more concerned about viewers getting confused with many symbols
than running out of symbols in R. Looking at the last example in
help("points"), I would say that there are 20-30 usable symbols.
Remember that you can also use text() to put multi-character text.
Regards, Adai
On Mon, 2005-08-08 at 13:42 -0700, Kerry Bush wrote:
Thank you. But I only need three classes of freqnencies (in another words, only three kinds of symbols) for 1-5, 5-10 and above 10, not to use different symbols for different frequencies. Otherwise, clearly R will run out of available symbols and the plot is also hard to view. Thank you anyway. --- Adaikalavan Ramasamy <ramasamy at cancer.org.uk> wrote:
Group by which variable ? If you mean the joint
distribution of 'x' and
'y' then something along the following lines
x <- rep( c(0.1, 0.2, 0.4, 0.5), c(5, 6, 10,
20) )
y <- rep( c(0.5, 0.6, 1.2, 2.5, 3.0), c(3, 8, 8,
18, 4) )
new <- factor( paste(x, y, sep="_") )
tb <- table(new)
pchcode <- cut(tb , c(-Inf, 1, 5, 6, 10, Inf),
labels=F)
tmp <- t( sapply( strsplit( names(tb),
split="_") , c ) )
df <- data.frame( x=tmp[ ,1], y=tmp[ ,2],
freq=as.vector(tb), pchcode
= pchcode -1 )
x y freq pchcode
1 0.1 0.5 3 1
2 0.1 0.6 2 1
3 0.2 0.6 6 2
4 0.4 1.2 8 3
5 0.4 2.5 2 1
6 0.5 2.5 16 4
7 0.5 3 4 1
And now to plot it, we use points() repeatedly.
plot( as.numeric(df$x), as.numeric(df$y), type="n"
)
for( i in unique( df$pchcode ) ){
w <- which( df$pchcode == i )
points( df$x[w], df$y[w], pch=as.numeric(i) )
}
I am sure someone else will come up with a neater
solution.
Can I also suggest that you try the following
plot( jitter(x), jitter(y) )
or better still the following
library(hexbin)
plot( hexbin(x, y) )
Regards, Adai
On Mon, 2005-08-08 at 11:57 -0700, Kerry Bush wrote:
suppose I have the following data 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))
If I plot(x,y) in R, I will only get seven
distinct
points. What I want to do is to use different
symbols
to show the frequency at each point. e.g. if the frequncey is between 1 and 5, then I
plot
the point as a circle; if the frequency is between
6
and 10, then I plot the point as a square; if the frequency is above 10, then I plot the point as a triangle. I am not sure how to do this in R. Can anybody
help me?
______________________________________________ R-help at stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide!
__________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com
On Mon, Aug 08, 2005 at 03:17:44PM -0400, Chuck Cleland wrote:
You might consider one of these approaches instead: plot(jitter(x), jitter(y)) or pdf(file="c:/AlphaExample.pdf", version = "1.4") plot(x, y, col = rgb(1, 0, 0, .2), pch = 16) dev.off()
sunflowerplot() is also useful for this (although it won't be as elegant as the pdf with alpha on screen, it looks better on paper). Tamas