简体   繁体   中英

Does anyone know how to plot the distribution of “Date” in R?

I have a data.frame with few columns, some are characters and some are numerics , one of them is Date . I would like to visualize that range of the Date but it's not very intuitive how to do that.

Does anyone have any good suggestion for approach? I am not asking for specific codes just the directions of how to get an idea what's the distribution of the Dates are. But if you have codes for demonstrating purpose, I would appreciat that as well.

Update

Here's a demo code for dates.

date3 <- data.frame(example=c(as.Date("01/01/2011", format="%m/%d/%Y"), as.Date("02/01/2012", format="%m/%d/%Y"),  as.Date("03/01/2013", format="%m/%d/%Y")))

As an alternative to histograms and box plots, it can be useful to see the dates on a calendar. Building on the example provided by googleVis...

library(googleVis)
library(tidyverse)

date4 <- c(as.Date("01/01/2011", format="%m/%d/%Y"), as.Date("02/01/2012", format="%m/%d/%Y"),  as.Date("03/01/2013", format="%m/%d/%Y"))
Date_seq =  seq(from = as.Date('2011-01-01'), to = as.Date('2013-12-31'), by = '1 day')
Dates_of_interest <- rep(0, n = length(Date_seq))
Dates_of_interest[Date_seq %in% date4] <- 1 

df <- data_frame(Date_seq = Date_seq, Dates_of_interest = Dates_of_interest)

Cal <- gvisCalendar(df, 
                    datevar="Date_seq", 
                    numvar="Dates_of_interest",
                    options=list(
                      title="Dates of interest",
                      height=320,
                      calendar="{yearLabel: { fontName: 'Times-Roman',
                               fontSize: 32, color: '#1A8763', bold: true},
                               cellSize: 10,
                               cellColor: { stroke: 'red', strokeOpacity: 0.2 },
                               focusedCellColor: {stroke:'red'}}")
)
plot(Cal)

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM