I'm looking to simply display in one plot the production(geom_line) and the import(geom_bar) of wheat over years with data pulled from faostat. So basically on the x-axis = year, on the y-axis = production, and on the final axis = import. Adding to that I would like to have the bars split by the country for import since there is more import from a certain country, but I don't wish to display all of them, only the top 3 and the rest should be in a new category "other".
I'm quite bad with the code in R but once I have the foundation I can figure out how to adjust the looks of it just need to figure out how to start.
Here I'm providing a simplified dataset, as described, in the bar plot I want to show only the 3 highest values and have the rest combined into a new category "other". And a geom_line should be displayed on top of that with a separate axis on the right side, for some reason the geom_line is not working for me.
import <- data.frame(country = c("USA", "USA", "EU", "NZ", "EU", "Bulgaria", "Romania", "Serbia"),
date = c("1991", "1992", "1994", "1995", "1991", "1991", "1991", "1991"),
value = c(1000, 500, 2000, 1500, 1000, 100, 500, 500))
production <- data.frame(date = c("1991", "1992", "1994", "1995", "1995"),
value = c(50, 45, 40, 39, 38))
ggplot(data = import, mapping = aes(x=date, y=value, fill=country)) +
geom_col()
ggplot(data = production, aes(x=date, y=value)) +
geom_line()
Any help or guidance in the right direction will be appreciated. Thank you in advance! Love this community always great with the help <3
