R studio Visualize data problem

Hello,
I am having trouble with a code that I am trying to create a histogram with the data I have. Everything is well in my environment. Would I need to revise my code?

# Render a boxplot of oil consumption per capita
#I put in the following:
ggplot(aes(x = oil_consumption_per_cap2$year, y = oil_consumption_per_cap2$consumption), data = oil_consumption_per_cap2) +
  geom_boxplot() +
  scale_x_discrete(breaks = seq(1960, 2015, 5)) +
  labs(title = "Oil Consumption per Capita by Country", x = "Year", y = "Consumption")
#I get:
Error: stat_boxplot() requires an x or y aesthetic.
Run `rlang::last_error()` to see where the error occurred.
In addition: Warning messages:
1: Use of `oil_consumption_per_cap2$year` is discouraged. Use `year` instead. 
2: Use of `oil_consumption_per_cap2$consumption` is discouraged. Use `consumption` instead. 


you would like a histogram, or a boxplot ?
You can study how to ggplot in general with this resource

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.