[R] Need help in ggplot

Md. Moyazzem Hossain ho@@@|nmm @end|ng |rom jun|v@edu
Tue Jun 28 16:07:38 CEST 2022


Dear R- Experts,

I hope that you are doing well.

I am facing a problem with adding color to a barplot. My target is to add a
bar color conditioning on the following

Values close to 1 represent "White" and values tend to 0 represent "Black".

However, I failed. The code is given below. I will be happy and thankful if
anyone helps me in this regard.

Thanks in advance.

library(ggplot2)
predictors=c("x1", "x2", "x3", "x4", "x5")
values=c(1.0, 0.67, 0.26, 0.18, 0.17)
prob=c(1.0, 0.001, 0.957, 0.924, 0.253)

df <- data.frame(predictors, values, prob)
ggplot(df, aes(x=predictors, y=values) ) +
  geom_bar(stat="identity") +
  coord_flip()+
  scale_fill_manual(values=c("gray(prob)"))

Best Regards,

*Hossain*

	[[alternative HTML version deleted]]



More information about the R-help mailing list