Hello and that lecture we're going to learn how to build a mean plot starts with a plot to.
I'm going to use the same data.
Graeme D-Mo. that contains information about a group of car owners and I'm going to create a million
plot representing the average income for each gender category male and female.
So the grouping variable will be dichotomous binomial with two categories.
First to load the package of block 2.
And now let's make some preparations for building their chart.
The main plot chart of earth that create the age of crane with the means of the gender groups with a
fountain Argerich other aggregates Thori.
I think you know it's from a previous to that term.
So for the variable incom we are going to compute the means for each gender categories.
So the grouping variable is introduced here by the option by and function the least and I'm going to
call it with date of brain and data that's Thuram analyzed view my data frame.
So here we have for each group female and male.
The average income in that column X the variable x.
OK.
Now we can draw the plot or in so he or we have to use first they function g on the line in order to
draw a line I must specify the data frame which is agie data with Ikhwan that call an X will contain
all the two values.
So here it is defined by the sequence 1 2 because we only have two categories male and female.
And that the X Y will represent the column EBEs in the data frame and data.
So this column.
OK.
Now let's play around the with the X is a bit the scale x will be discrete So I'm going to use this
fivepence K x and just create that name or the name of this case is gender and the Laubach are female
and male in this order from that date frame data.
And this can y either continues.
So I'm going to use this function K and y continues its name is income and the limit on 70 to 85.
Why I have chosen these limits because here the values are for May.
The average income.
Seventy three point zero or three and four female eighty four point thirty seven.
OK.
Now the last round of this.
And presto we have the line here so we can notice in their chart that the male subjects have an average
income lower than the female subjects that we can visualize the difference here and there.
And this graphs
of course we can change the line color and make it the be it the car.
So here in the genome line from when we pull the color equal to red and the side equal to one point
three that is caused by this one.
So we'll get to the car line.
The other options here are the same.
You can notice here in this chart there is always OK that would be all for the gender category.
And now with Bill the charge with the polygynous factor with the factor with three or more categories
of course we get a broken line this time of factor will be educational level.
Do it with five categories.
The procedure is the same for us using the aggregated function we compute the average income for each
category of education.
OK.
Let's do that and see the data from that data.
Ok so here you have the income the average income for each of the five education both and now we can
build our charge.
But you know just here in the genome line that function and a static option there is the act says the
x x x.
This story has five categories.
So it is defined by a sequence 1 to 5.
And on the y axis we call them from the data operator and data is represented.
K x has the name education level now and the levels are of course that the category of the variable
educational level you can see them here and this k y the y axis or it is continuous.
So I'm going to use here the oftens k y continuous.
The name is income and the limits are the 6 to 4 and one hundred sixty And that's from then.
OK.
So that broken line that our graph.
So here we can visualize the difference with an average being calm for all the five education levels.
Let go for now that they are grouped me and plot the grouping variable will be that car category Karaka.
So we're going to create the mean plot for the same variable education levels but we will have three
lines this time one line for each car category economy standard and luxury cars.
How to do that.
Well first of all that create real data upgrades for the economy standard and luxury cars using the
brackets.
So we will call them the more easy for the economy cars and the more s t for the standard cars and the
more you for the luxury cars that create them all at once.
OK.
And now using the same aggregate function we will build three data frames that will contain the average
income for each application level.
So the birth date of crame a GGC contains the average income by educational level but for the owners
of the economy car of course as the second date frame A-G GST will continue to semi-informed is the
same information.
The income by education level but for the owners of the town and cars.
And finally the AGC as you data frame will contain the same information.
The average income by application level but for the owners of luxury cars let's round them all.
And now let me visualise our data grave's the so that the data frame every day.
See here we have the data for the economy cars.
Here we have the data for the owners of standard cars.
And here we have the day to day average income for the owners of luxury cars.
And now we can plot the three lines on the same chart.
You notice that we have here three G on the line functions the data frame for each one will be AGC agency
Asti and A-G and you respectively of course
the x axis will be defined with a stack with a stack on from 1 to 5 because the grouping variable education
has five categories and the y axis will represent the average income income here is the variable x from
each day is operating agent is the key.
And you and using the caller often we get a different color to each line.
Green for the column a car with the red for the standard car and blue for the luxury cars and we define
the case for the two acted in exactly the same way as previous that acted all and around it all just
a moment.
So here you can view the three lines or each car category.
So where the blue line corresponds to to the luxury cars.
So they have the higher income as expected.
The red line corresponds with the standard cars and the green line parts to the economy cars.
The owners have the lowest income or as is expected.
Now this chart does not have a lag John that had a look at just like the previous lectures.
OK.
So first of all we will define a variable LGT with a function scale color manual the name will be let's
say legend.
And with the function values we assign a color to each car category green to economy down red to standard
and blue to luxury.
And here we are in just a moment.
In that DZIEDZIC plot function you noted here that in the Jhoom line fanfares you have that color option
in the æsthetics option here.
So between the bare Athersys.
OK.
So the color for the variable for the category economy is green for the variable for the category Tander
stories the ride for the category luxury blue.
Why do we put the color option and they started options option because the way the program now that
it must add a legend to the chart and to actually to actual am and the legend we have had you do very
well at the end here.
Please don't forget that that's around there that's all
OK.
First I had to find that to store the variable Lijun story.
I got an error.
So now I find the vagal imagined.
And now I can raise the charge that
just moments.
So you have the legend here.
Right.
So now our chart looks really cool.
That's all.
Thank you.