I have 2 variables
price for white cars has length 106 and price for black cars has length 71
I need to do bar plot with xlap="white","black" , ylab="mean of price" like this bar
How about this:
dat <- data.frame(
color = rep(c("white", "black"), c(106, 71)),
price = rnorm(177, 20, 5)
)
ag <- aggregate(dat$price, list(dat$color), mean)
ag
#> Group.1 x
#> 1 black 19.89868
#> 2 white 20.60027
barplot(ag$x, names.arg=ag$Group.1, ylim=c(0, max(ag$x)*1.075), col=c("gray25", "white"))
text(c(.7, 1.9), ag$x+1, round(ag$x, 1))
Created on 2022-04-22 by the reprex package (v2.0.1)