vistime icon indicating copy to clipboard operation
vistime copied to clipboard

Add days after a date in the x-axis

Open carlanetto opened this issue 4 years ago • 9 comments

Hi! I need to create a timeline that shows the number of days after the start and not specific days in the x-axis. Is there a way of doing it? Thanks in advance Best regards

carlanetto avatar Jun 01 '20 13:06 carlanetto

I can't imagine what the result would look like, could you draw a picture or sketch?

shosaco avatar Jun 02 '20 07:06 shosaco

It would look like any gantt chart, when you do not know yet when something will happen in time, just the order of events and number of days of each task:

https://images.app.goo.gl/SKx5D6EMuJedi4dP7

carlanetto avatar Jun 04 '20 12:06 carlanetto

The screenshot behind your link does show projects in the y-axis, not days, so kindly specify what you have tried and what is failing, thanks :)

shosaco avatar Jun 04 '20 14:06 shosaco

The image says on the x-axis: “days of the month”. I wish to add numbers of days and not specific dates. Your package right now gives back an error and requested that the start and the end to be in a date format.

I want to add to the timeline: this project should start on day 6 and go until day 10 after the start of the project (that I don’t know when it will be). But without a month or year.

carlanetto avatar Jun 04 '20 15:06 carlanetto

The image is of what I want to do and not an output of your package... Sorry, I thought that was clear

carlanetto avatar Jun 04 '20 15:06 carlanetto

So you are talking about the x-axis, not the y axis and already have tried something in code - please post this code as a starting point. The solution will be to convert your integer days into dates by using as.Date(2000-01-01) + your_days_vector.

shosaco avatar Jun 05 '20 06:06 shosaco

I do not want it to show up like dates, so I don’t want to transform it do date. I just would like that the package does not require the input to be in a date format. This way the package could be applied in different contexts. But I will look for another solution in another package.

The code I am using is the example you give in the documentation.

Thanks for the attention

carlanetto avatar Jun 05 '20 09:06 carlanetto

So you are talking about the x-axis, not the y axis and already have tried something in code - please post this code as a starting point. The solution will be to convert your integer days into dates by using as.Date(2000-01-01) + your_days_vector.

Thanks... indeed I am using it in x-axis, and I corrected it on the question. But it could actually be a nice idea to be able to flip the visualization.

carlanetto avatar Jun 05 '20 09:06 carlanetto

I used my suggestions and formatted the x-axis accordingly:

data <- read.csv(text="event,start,end
                       Phase 1,1,10
                       Phase 2,8,15", stringsAsFactors=FALSE)
data$start <- as.Date("2000-01-01") + data$start - 1
data$end <- as.Date("2000-01-01") + data$end - 1
gg_vistime(data) +
    scale_x_datetime(breaks = seq(min(as.POSIXct(data$start)), 
                                  max(as.POSIXct(data$end)), 
                                  "days"), 
                     date_labels = "%d") + 
    xlab("Day")

grafik

shosaco avatar Jun 05 '20 10:06 shosaco