0

Create a plot with cars dataset and attribute speed along the X axis and distance in y axis . Label the axes.

I have done this programming still there is some problem:

plot(cars,xlab="speed",ylab="distance")

Even though everything seems correct the terminal doesn't move to the next part

Maurits Evers
  • 49,617
  • 4
  • 47
  • 68
user7826397
  • 21
  • 1
  • 6
  • Are you getting an error message or the plot doesn't show in a device window? – Juan Bosco Mar 10 '20 at 01:18
  • If my answer will be correct then the environment will automatically allow me to continue further but it says that complete the task which means it isn't – user7826397 Mar 10 '20 at 09:02

1 Answers1

1

What environment are you using? I was able to execute the following code and produce the plot you want using both RStudio and R directly in the terminal.

library(MASS)

plot(cars, xlab="Distance", ylab="Speed")

If you're running straight from the terminal then you'll need to specify a window to pop up. The following question has an answer that outlines what to do depending on your operating system:

How to pop up the graphics window from Rscript?

So, for example, if you don't have your system configured to automatically open the plot window, and you're running on a mac, the following code will produce what you want directly from running R in the terminal:

library(MASS)
X11()
plot(cars, xlab="Distance", ylab="Speed")
lincolnck
  • 302
  • 1
  • 12
  • I was doing this in katacoda training. I was able to do the same in the rstudio but not in Katakoda – user7826397 Mar 10 '20 at 06:40
  • I see. I am only vaguely familiar with Katakoda, do you have an editor where you can write and save scripts, and then a command line from which you can run them? Or are you only working with the command line? – lincolnck Mar 10 '20 at 13:16