The lattice library has a large number of graphing commands, which you can freely explore. In general, I opted to occupy bookstores only when it makes things substantially easier. Now we are going to see an option to display this data without occupying lattice.
Instead of graphing separately, we can make the circles in the scattergram a different color based on the group to which the person belongs.
Making the graph separately for men and women is more than enough, but when explaining how to include both in the same graph we are going to take advantage of explaining some more fundamental functions of R and exemplifying how we can use the functions creatively to arrive at the result that we want.
This simply creates an object with a two-color list. The c () function, which we had already covered above without explaining, simply concatenates the elements so that they are in a list.
Instead of occupying rainbow () or repeating the colors that will be occupied in each graph, when you are making a report it can be useful to make a custom color palette occupying this function. This also allows you to change the colors of all the graphics without having to modify each of the commands. Just replace the colors in the object they created.
What we now have is a list where item 1 is “red” and item 2 is “blue.” The factors (categorical variables) are also coded as a list. The function
shows the values that the generof variable can have. The first element is “Woman”, and the second element is “Man”.
The grace is that now we can replace “Woman” and “Man” by “red” or “blue” as they appear in the “colors” object:
If it seems weird to you, don’t worry, it doesn’t matter why it works. What matters is that we can make the following scatter plot:
We can also include a line for each group. This requires occupying only male or female participants as appropriate.
Notice that now the number is after the comma, because it refers to a column. If we want to know the sentimental situation of participant 86, we have to execute
But the row and column numbers can also be logical expressions, which allows us to select part of the database according to some condition, for example that the participants are men:
Notice that the condition is placed before the comma, we want to select the rows where the value of generof is “Male”.
The use of “==” is also important. AND