Skip to content

plotting

7 messages · R. Michael Weylandt, David L Carlson, John Kane +2 more

#
I think you'll find this easiest with ggplot2:

library(ggplot2)

ggplot(dat, aes(x = value, y = time, color = group, symbol = id)) +
geom_point()
# symbol = might not be the right argument -- I'm doing this from memory

or similar....

MW
On Thu, Mar 14, 2013 at 3:46 PM, li li <hannah.hlx at gmail.com> wrote:
#
It is easy to do in base graphics, but probably a bad idea just because it
is very hard to decode the symbol/color combinations. I added a crude
legend:

# Provide reproducible data
set.seed(42)
value <- round(rnorm(20), 2)
time <- round(runif(20)*10, 1)
group <- sample(1:4)
id <- sample(1:5)
dta <- data.frame(value, time, group, id)

# Plot and legend
plot(value~time, pch=id+20, col=group, bg=group, cex=1.25)
legend("bottomright", as.character(1:4), pch=16, 
  col=1:4, bty="n", inset=c(0, .045), title="Group")
legend("bottomright", as.character(1:5), pch=21:25, col="gray", 
  inset=c(.1, 0), bty="n", title="ID")

----------------------------------------------
David L Carlson
Associate Professor of Anthropology
Texas A&M University
College Station, TX 77843-4352
#
Also going from memory Michael's ggplot should almost work but I think yo need to change  symbol = id in the aes statement to 
geom_point(aes(shape = id)) although it may work in the first aes() statement. 

John Kane
Kingston ON Canada
____________________________________________________________
FREE 3D MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks & orcas on your desktop!
#
I just appropriated your data set and tried it in ggplot2 and your objection looks valid there as well.

And Michael was right, the shape command can go in the first aes statement.

  
library(ggplot2)    
p  <-  ggplot(dta  , aes(time, value, 
        shape = as.factor(id) , colour =as.factor(group ))) + 
        geom_point()
  p 

John Kane
Kingston ON Canada
____________________________________________________________
GET FREE SMILEYS FOR YOUR IM & EMAIL - Learn more at http://www.inbox.com/smileys
Works with AIM?, MSN? Messenger, Yahoo!? Messenger, ICQ?, Google Talk? and most webmails
#
On 03/15/2013 02:46 AM, li li wrote:
Hi Hanna,
You will probably want to dress this up a bit:

# rustle up some data
test.df<-data.frame(value=rnorm(80)+4,time=sample(0:23,80,TRUE),
  group=rep(LETTERS[1:4],each=20),id=rep(1:4,each=20))
# plot it
plot(test.df$time,test.df$value,col=test.df$group,pch=test.df$id)

Jim