You get that error your x-variable is a category and you can’t join them into a line. I guess you would need a bar plot (I flip the plot so that the types can be read, you can remove coord_flip() if you don’t need that) :
fluid_milk_sales %>%
filter(year == 2017) %>%
ggplot(aes(x = reorder(milk_type,pounds), y = pounds)) +
geom_col() + xlab("milk_type") + coord_flip()
Or if you want like a lollipop plot, it goes like:
fluid_milk_sales %>%
filter(year == 2017) %>%
ggplot(aes(x = reorder(milk_type,pounds), y = pounds)) +
geom_point() +
geom_segment(aes(xend = milk_type, yend = 0)) +
coord_flip() + xlab("milk_type")
If you really want to force a line, which I think doesn’t make sense (note I reorder with the negative to start with the highest):
fluid_milk_sales %>%
filter(year == 2017) %>%
ggplot(aes(x = reorder(milk_type,-pounds), y = pounds,group=1)) +
geom_line() + xlab("milk_type")
CLICK HERE to find out more related problems solutions.