Reputation: 85
I have the following graphic:
But I need it to be like this:
My code is:
n_papers<-c(6,4,5,1,6,2,1)
paper_ui<-c(3,2,4,0,1,1,0)
methods<-c("AR","ARMA",'ARIMA',"SARIMA","Loess \n decomposition","Classical \n decomposition","Exponential \n smoothing")
df <- data.frame(n_papers,paper_ui,methods)
ggplot(df) +
aes(x = methods, y = n_papers,fill=paper_ui) +
geom_bar(show.legend = FALSE,stat="identity",position = "dodge")+
labs(x=NULL, y = "Number of papers") +
theme_bw()+
theme(panel.border = element_blank(), panel.grid.major = element_blank(),
panel.grid.minor = element_blank(), axis.line = element_line(colour = "black"))
And I need the blue to be the same to all the bars color="dodgerblue4". Thank you for the help!
Upvotes: 0
Views: 492
Reputation: 124183
You could add a second geom_bar
or geom_col
like so:
library(ggplot2)
ggplot(df) +
aes(x = methods) +
geom_col(aes(y = n_papers, fill = "total"))+
geom_col(aes(y = paper_ui, fill = "ui"))+
labs(x=NULL, y = "Number of papers") +
scale_fill_manual(values = c(total = "grey", ui = "dodgerblue4")) +
theme_bw()+
theme(panel.border = element_blank(), panel.grid.major = element_blank(),
panel.grid.minor = element_blank(), axis.line = element_line(colour = "black"))
Upvotes: 1