0

I have 19 tags which were deployed and reported at different times throughout the summer and fall. Currently I am trying to create a plot to display the times of deployment and reporting so that I can visualize where there is overlap in data collection. I have tried several different plotting functions including plot(), boxplot(), and ggplot(). I have gotten close to what I want with boxplot() but would like the box to extend from the start to the end date and eliminate the whiskers entirely. Is there a way to do this or should I use a different function or package? Here is my code, it probably isn't the most efficient since I'm somewhat new to R.

note: tnumber are just the tag numbers I used. The dates were all taken from different data sets.

dep.dates=boxplot(t62104[,8],t40636[,8],t84337[,8],t84353[,8],t62103[,8],
                  t110289[,8],t62102[,8],t62105[,8],t62101[,8],t84360[,8],
                  t117641[,8],t40643[,8],t110291[,8],t84338[,8],t110290[,8],
                  t84363[,8],t117639[,8],t117640[,8],t117638[,8],horizontal=T,
                  main='Tag deployment and pop-up dates',xlab='Month',
                  ylab='Tag number',names=c('62104','40636','84337','84353',
                  '62103','110289','62102','62105','62101','84360','117641',
                  '40643','110291','84338','110290','84363','117639','117640',
                  '117638'),las=1)
user1997414
  • 189
  • 3
  • 10

1 Answers1

1

Something like this will work if all you care about is ranges.

require(ggplot2)

require(SpatioTemporal)

data(mesa.data.raw)

require(data.table)

out <- as.data.table(t(apply(mesa.data.raw$obs, 2, function(.v){ 
    names(.v)[range(which(!is.na(.v)))]
})),keep=TRUE)

setnames(out, "rn", "monitors")


ggplot(out, aes(x=monitors, y=V1, ymin=V1, ymax=V2,)) + geom_crossbar() + coord_flip()
ggplot(out, aes(x=monitors, ymin=V1, ymax=V2)) + geom_linerange() + coord_flip()

The first ggplot call creates horizonal bars but I can't figure out how to get rid of the center line so I just put it at the start.

The second plot creates horizontal lines, which I think looks better anyway.

Michael
  • 5,808
  • 4
  • 30
  • 39
  • Thanks for the help but so far I haven't been able to get this to work. I've never used these packages before so I'm unfamiliar with how they operate and this may be a stupid question but when I substitute my data in for (mesa.data.raw) I get this warning:Warning message: In data(date.time) : data set ‘date.time’ not found - What am I missing? I read in the data as I normally would but it doesn't seem to recognize it. I appreciate any help you can give me. – user1997414 Jan 22 '13 at 13:38
  • The `data` function just loads the sample dataset `mesa.data.raw` from the `SpatioTemporal` package. Try to get your data structured exactly as `out` is immediately prior to the `ggplot` call. It doesn't have to be a `data.table`, a normal `data.frame` will work. Your `data.frame` should have a column corresponding to tags (`monitors`), a column corresponding to start date (`V1`), and a column corresponding to end date (`V2`). If you need more help, you'll have to produce a reproducible example http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – Michael Jan 22 '13 at 18:57