Good job! The bars in the barplot are displayed in the same order as the levels in the price_category
factor, that is "high", "low", "medium". This is their alphabetical order. However, it makes more sense to order the levels as high-medium-low or low-medium-high.
To define the order of factor levels, you can use the optional levels
argument. For example, if you would like to change the order to "high", "medium", "low", you can do the following:
houses$price_category<- factor(houses$price_category, levels = c("high","medium","low"))
The levels
argument allows you to specify the levels your factor will use and in what order they should be defined. In this case, c("high", "medium", "low")
tells R to create a factor whose levels are defined as "high", "medium", and "low", in that specific order.