Reputation: 55
Here's what I have done so far.
Now how can I add time on top of the graph?
Also, wondering how to use the R code lines on the text instead of attaching as a file.
Upvotes: 0
Views: 3413
Reputation: 598
Please specify what you need more explicitly, I'm going to assume you want just points given your data. Also when you post example data, post it in text not an image so we can copy it.
Use the ggplot2 library for nice plotting. I used a tibble from the tidyverse instead of a dataframe but you can use either.
# Make your data frame but different months
data.cars <- tibble(Cars = c("Toyota", "Honda", "Nissan"), Month = c("Jan",
"Feb", "Mar"), `Distance(km)` = c(124,221,154), `Time(min)`= c(21,34,23))
# Make the Months column a factor instead of strings (Jan=1, Feb=2, etc)
data.cars$Month <- as.factor(data.cars$Month)
# Make a plot with a common x-axis - the month and different y-axes
ggplot(data.cars, aes(x = Month)) +
geom_point(aes(y = `Distance(km)`, color = "blue")) +
geom_point(aes(y = `Time(min)`, color = "red"))
Upvotes: 1