2

When I try to graph Shares vs. Time (formatted as 4:56pm, e.g.) in a bubble chart, the chart that is produced has the x-axis displaying 10, 20, 30, and 40 -- not the time values in the Time vector. Every other vector graphs out fine.

This is what I typed in:

symbols(reposts$Time, reposts$Shares, circles=reposts$Bubble.Size, inches=.5, 
         fg="3",    bg=(reposts$Lineup), xlab="Time", ylab="Shares")

I'm wondering if there's a problem with how the elements in my "time" column are formatted. Does anyone have any ideas?

ETA: Because I'm new here, I'm unable to post screenshots atm. Here's the data I'm working with:

ETA2: Screenshots posted.

DATA$Time

10:42am, 7:57pm, 6:46pm, 10:37pm, 12pm, 9:06pm,  2:04pm,  7:20pm,
7:46pm,  9:18am, 1:11pm, 9:02pm, 6:05pm,  9:57pm,  11:22am, 7:16pm,
1:33pm,  10:11pm,  8:18am,  4:13pm,  1:13pm,  8:08pm,  12:07pm,  6:58pm 
3:32pm,  9:38pm, 12pm, 7:12pm,  3:37pm,  8:30pm,  1:07pm,  9:53pm, 
11:07am, 6:33pm,  6:35pm,  12:48pm, 6:31pm,  10:01pm, 11:34am, 7:26pm,

39 Levels: 1:07pm 1:11pm 1:13pm 1:33pm 10:01pm 10:11pm 10:37pm 10:42am 
11:07am 11:22am ... 9:57pm

My code:

symbols(DATA$Time, DATA$NUMBERSET1, circles=DATA$NUMBERSET2, inches=.5, 
         fg="3", xlab="Time", ylab="NUMBER SET 1")

Output: A bubble chart with the correct labels/numbers on the y-axis but labels of 0-40 on the x-axis.

Screenshot of Output

LNA
  • 1,427
  • 3
  • 24
  • 37
  • Um... without seeing what you've done, it's a little hard to guess. See http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – Ed Staub Oct 16 '11 at 01:34
  • 1
    Could you use `dput` to dump `DATA` in a format that is easy to use in trying our own examples? My quick suggestion (too quick for an answer) would be (1) don't draw the axis the first time (include `axes=FALSE`) and then use `Axis` to add a properly formatted axies or (2) try `library(ggplot2); qplot(Time,NUMBERSET1, size=NUMBERSET2, data=DATA)` – Ben Bolker Oct 16 '11 at 15:18
  • 1
    I suspect the times are being interpreted as a factor, and the numbers are the ordinal values of the factor. I'd guess that when there are too many to label individually, it just shows the ordinal values intermittently. I'm an R newbie, though, and don't know what to do about it. I think you need to apply some function that will parse $Time - which is just a string - into time. Al R's answer below does this, I think. – Ed Staub Oct 16 '11 at 21:15

1 Answers1

2

Check out the following example which makes use of one of the date/time classes in R:

tms<-strptime(c("10:00AM","12:00PM","10:00PM"),format="%I:%M%p")
vals<-c(1,5,3)
radii <-c(2,4,6)
symbols(tms,vals,radii,xaxt='n')
axis.POSIXct(1, at=tms, format="%I:%M%p")

HTH

Al R.
  • 2,430
  • 4
  • 28
  • 40
  • Follow-up question: Is it possible to type some variation of tms<-strptime(c("DATA$Time"),format="%I:%M%p") so I can save the work of typing out each of the times in that vector? I tried the above, but it resulted in an NA when I tested what tms output to. – LNA Oct 17 '11 at 00:58
  • Never mind, just discovered that strptime(DATA$Time,format="%I:%M%p") is what I should have tried. – LNA Oct 17 '11 at 01:02