Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to plot graph like this using R

enter image description here

I don’t even know the name of this plot and what kind of data is required to make this, so sorry I don’t really have a minimal reproducible sample. with x axis the time and y axis all the variables,in each period each variable can be selected or not selected, indicated by the blue colour.

this plot is from Freyberger, Joachim, Andreas Neuhierl, and Michael Weber. "Dissecting characteristics nonparametrically." The Review of Financial Studies 33.5 (2020): 2326-2377.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You could use ggplot.

First we’ll create some plausible sample data:

set.seed(1)

df <- data.frame(on_off = c(replicate(26, cumsum(rnorm(20)))) > 3,
                 year = rep(2001:2020, 26),
                 factor = rep(LETTERS, each = 20))

And the plotting code is something like this:

library(ggplot2)

ggplot(df, aes(year, factor, fill = on_off)) +
  geom_tile() +
  scale_fill_manual(values = c('TRUE' = 'blue2', 'FALSE' = 'white')) +
  theme_classic() + 
  theme(legend.position = 'none')

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading