0

Using instructions and data from this link: https://people.math.carleton.ca/~davecampbell/datasets/2020/07/24/trade-data-monthly-exports-of-grains-open-canada/

"First subset the data so that you are only considering 
 two commodities: “Barley”, “Oats”. Make sure you color the points with the type of commodity. Include in your plot one single regression line for this subset of the dataset, add a second regression line for this subset of data, but make sure you force the line to have a zero intercept."

Currently my code looks like this but error of unknown column 'total' is coming up. Not sure how to plot a regression line with a subset within data:

export_data |> group_by(year, Commodity, Destinations) |> filter(Commodity == "Barley" | Commodity == "Oats") |> summarize(total = sum(VALUE)) |> subset(Destinations == "Total exports, all destinations") |> ungroup() |> ggplot( aes(x = year, y = total, group = Commodity)) + labs(y = "total export (tonnes)") + geom_point(aes(color = Commodity)) + ggtitle("Total Barley and Oats export to all destinations") x <- export_data$year y <- export_data$total abline(lm(y ~ x, data = export_data), col = "yellow") 
1
  • Maybe look here. Commented Oct 19, 2021 at 16:12

1 Answer 1

0

you first need to swtich x and y. It is y against x.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.