Home > Mobile >  Plot from one column in R using plot
Plot from one column in R using plot

Time:04-29

 starwars <- dplyr::starwars
 plot(starwars[,'mass'],
 )

My task is to create a graph line type for the "mass" column using plot(). I started my code but i only get one horizontal line.

CodePudding user response:

You need to define your X variable. If you want to see how "mass" changes across a gradient, you need to define the gradient:

plot(starwars$mass ~ starwars$X)

You can add a straight line:

plot(starwars$mass ~ starwars$X)
abline(lm(starwars$mass ~ starwars$X))

CodePudding user response:

I agree with CescGV. The route in that answer should give you a scatter plot and you need to define an X variable.

If you are looking for a some kind of bar graph or a histogram you could use

hist(starwars$mass)

to tell you the frequency of mass in your df.

  • Related