CodeInfoNet

Learn programming on the go!

Subsetting and visualizing subsets with matplot

Legend() function:

This function is used to show legend in a graph. It expects few parameters as listed below:

i. Position: this is important to specify where we want to show our legend in a graph. Position can be specified as “bottomleft”, “bottomright”, “left”, “center” and so on.

ii. Inset: it specifies how far we want to move it from the specified position.

iii. Legend: the actual dataset which we want to use as a legend.

iv. Colours: these colours should be same as the colours which are mentioned in matplot function

v. Pch: plotting characters also should be same as plotting characters which are mentioned in matplot function

Ex. legend(“topleft”, legend=Players, col=c(1:4,6), pch = 15:18)

Execute these two lines together to see the result.

Visualizing subsets

It looks good, isn’t it?

You can try as many options as you can to get better hands on this. You can use different matrices, different combinations in it. These combinations you can try in matplot function.

#these combinations you can try in matplot function.

t(FieldGoals)
t(FieldGoals/Games) #Average Goals
t(FieldGoals/FieldGoalAttempts) #Accuracy of Goals

matplot(t(FieldGoals/Games), type = "b", pch = 15:18,
col=c(1:4,6))
legend("bottomleft", legend=Players, col=c(1:4,6), pch = 15:18)

matplot(t(FieldGoals/FieldGoalAttempts), type = "b", pch =
15:18, col=c(1:4,6))
legend("bottomleft", legend=Players, col=c(1:4,6), pch = 15:18)

Above code is also available on CodeInfoNet’s git repository. Check it out and try. Here is the url: Visualizing with matplot

Keep me posted if you have any query about the article “Subsetting and visualizing subsets with matplot”. Your advice is priceless. Please provide any feedback regarding the quality of explanation or the complexity of content using below feedback form.

Feel free to comment or reach us directly via mail. Also you can contact us by Facebook, linkedin, twitter, instagram any of the platform you feel comfortable with.

Keep Learning. Keep Coding.

Sumit Rajguru

Back to top