0

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

Phil
  • 7,287
  • 3
  • 36
  • 66
No Uce
  • 23
  • 5

1 Answers1

1

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)

DaveArmstrong
  • 18,377
  • 2
  • 13
  • 25