How do I display all legends in R ggplotly? As of now it only displays the legends for matching data.
Here is what I have done so far:
library(ggplot2)
library(plotly)
schoolname <- c("Xavier", "Dakota")
value <- c(34,50)
df <- data.frame(schoolname,value)
ggplot(df, aes(x=schoolname, y=value,
fill = cut(value, breaks =c(0,34,69,100),
labels = c("Failed - <65%",
"Pass - 65%",
"Excellent - 80%")))) +
geom_bar(stat = "identity",position="dodge", width=0.5, color = "#333333") +
geom_text(aes(x=schoolname, y=value + 4.1,
label = paste0(value), tooltip = NULL),
inherit.aes = F, color='black',
position = position_dodge2(2), size=4, vjust=1.5) +
xlab("School Name") +
ylab("Result (%)") +
theme(plot.title = element_text(size = 18, hjust=0, vjust=0)) +
scale_y_continuous(limits = c(0,100))+
scale_fill_manual(values = c("Failed - <65%" = "#ea9999",
"Pass - 65%" = "#ffc8aa",
"Excellent- 80%" = "#d4edbc")) +
theme(legend.position = "top") +
guides(fill = guide_legend(title = "Result", override.aes = list(size = 4))) -> p


