tk001
tk001

Reputation: 21

How to create pattern table in R

I would like to make a table like the one below in R. I am not sure what the table is called and packages that could do that in R.

# I would like the create the following table in R

table graphic

Below is what my data set looks like:

dat1 <- data.frame(ani=c("cat","dog","frog","fish","rat","snake","chicken"),
               year=c(2015,2016,2015,2018,2019,2017,2018),
               start_date=c("01-Jan-2015", "30-Mar-2016","08-Aug-2015",
                            "25-Nov-2018","05-Apr-2019","03-Mar-2017",
                            "11-Oct-2018"),
               end_date=c("02-Jan-2016","30-Jun-2016","07-Nov-2015","24-Mar-2019",
                          "04-Jul-2019","02-Jun-2017","10-Dec-2018"))

Upvotes: 2

Views: 110

Answers (1)

s_baldur
s_baldur

Reputation: 33488

Here is something you might want to play around with:

library(ggplot2)

# May need to Sys.setlocale("LC_TIME", "C")
dat1$start_date <- as.Date(dat1$start_date, "%d-%b-%Y")
dat1$end_date <- as.Date(dat1$end_date, "%d-%b-%Y")

ggplot(dat1) +
  geom_segment(aes(x = ani, xend = ani, y= start_date, yend = end_date), size = 10) +
  coord_flip()

enter image description here

Upvotes: 2

Related Questions