0

Here's what I have done so far.

enter image description here

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.

0

1 Answer 1

1

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"))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.