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")
CodePudding user response:
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"
)