I have a dataset with multiple models of motorcycles concatenated with their cc's. When plotting these in ggplot with a corresponding value, they are out of order due to _
used in between the model and cc concatenation.
How can I order the x_axis on the graph by one column (an order column) and label from the model_cc concatenation column?
I have tried this to no avail:
ggplot - ordering x-axis labels by multiple columns
Here is some example code:
> library(tidyverse)
>
> df <- data.frame(x_labels = c('A_1', 'A_100', 'A_2', 'A_200'),
> x_order=c(1, 3, 2, 4), y=c(100, 300, 200, 400)) df
>
> ggplot(data = df, aes(x = x_order, y = y)) + geom_point() +
> geom_line()
>
> ggplot(data = df, aes(x = x_labels, y = y)) + geom_point() +
> geom_line()
The first graph is what I want the order to be in, only with the x_labels
as the actual labels. The second graph is the correct labels, but not the correct order.