user1997414
user1997414

Reputation: 189

trying to plot ranges of dates

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)

Upvotes: 0

Views: 198

Answers (1)

Michael
Michael

Reputation: 5898

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.

Upvotes: 1

Related Questions