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

Need to put different color for same bar in vistime based on percentage

I need different color based on percentage. For example for the same bar, I need 60 % in red and other 40 % of the same bar to be blue.

pres <- data.frame(Position = rep(c("President", "Vice"), each = 3),
                       Name = c("Washington", rep(c("Adams", "Jefferson"), 2), "Burr"),
                       start = c("1789-03-29", "1797-02-03", "1801-02-03"),
                       end = c("1797-02-03", "1801-02-03", "1809-02-03"),
                       color = c('#cbb69d', '#603913', '#c69c6e'),
                       fontcolor = c("black", "white", "black"))
    vistime::vistime(pres, events="Position", groups="Name", title="Presidents of the USA")

>Solution :

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

You have a color column in your data frame. You can just change this to change the colors of the bars:

 pres <- data.frame(Position = rep(c("President", "Vice"), each = 3),
                       Name = c("Washington", rep(c("Adams", "Jefferson"), 2), "Burr"),
                       start = c("1789-03-29", "1797-02-03", "1801-02-03"),
                       end = c("1797-02-03", "1801-02-03", "1809-02-03"),
                       color = c('red', 'blue', 'green'), # Changed this line
                       fontcolor = c("black", "white", "black"))


vistime::vistime(
    pres, 
    events="Position", 
    groups="Name", 
    title="Presidents of the USA"
)

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