So, before we can plot something which just need to have a little bit of data
that's very easy to create.
That is a rnorm function which samples from a normal distribution.
So by default we have mean zero and standard deviation one so let's sample hundred points here.
And let's do the same for y.
and actually increase the standard deviation a bit.
And now we create a data frame and it’s data.frame and you say just (x,y).
If you now view this data frame we see here
that you have the two columns
And you see here the numbers are a bit higher
because the standard deviation is higher.
And now we can plot it.
So we have to import a library (ggplot2).
And then we can actually plot it so we say ggplot
plus parameters of course the data frame
And I won't go into detail here
because ggplot is relatively complex
but a very, very powerful library.
We are basically saying here that we want to draw points.
So you see here that on the x-axis and the y-axis
we are just plotting those points.
Okay, now let's actually plot something more nicely.
So there is a data frame build into R which is called mtcars.
And it has different types of cars, and their properties.
So it's a nice data set to play with.
And as I said ggplot2 is relatively complex
so I'm just copy-pasting the code
for plotting something really nicely.
So this is basically the weight of the car over the mileage.
And you see here the more heavy the car gets,
the less is the mileage.
And in addition to that you are also drawing
a regression line and also a confidence interval or a standard deviation.
So that's pretty cool with only two lines of code
You can create plots which you find
in the best (scientific) publications because the best publishers
often use R and ggplot2 for creating that plot.
Okay, I hope this helps.
If you have any further questions,
please let me know in the Comments section below.
And have a nice day. Bye!