Reputation: 995
I'm trying to filter a dataset within ggplot()
, and display a set of line charts for various countries with a population under 5 million.
I have the dataset locally saved to my computer, but I just put in the github address for convenience.
library(ggplot2)
load('https://github.com/inspectordanno/food_production_r/blob/master/countriesbyFood.rdata')
ggplot(countriesbyFood[countriesbyFood$Item=="Wheat and products" &
countriesbyFood$POP_EST < 5000000, ]) +
geom_line(aes(x = Year, y = Amount, color = Element)) +
facet_wrap(~Area)
I'm getting:
Error: Must request at least one colour from a hue palette.
Upvotes: 0
Views: 1056
Reputation: 389047
Few changes in the code and it works for me after loading the data.
library(tidyverse)
countriesbyFood %>%
mutate(POP_EST = as.numeric(as.character(POP_EST))) %>%
filter(Item == "Wheat and products" & POP_EST < 5000000) %>%
ggplot() +
geom_line(aes(x = Year, y=Amount, color=Element)) +
facet_wrap(~Area)
Upvotes: 1