Warning: Parameter 2 to wp_hide_post_Public::query_posts_join() expected to be a reference, value given in /home/rexercis/public_html/wp-includes/class-wp-hook.php on line 286
In the following exercises we practice how to customize a scatterplot. We will use
axis , to add an axis;
mtext to add a text; and
legend to add a legend. Moreover we practice how to add details in every stage. We will use the mtcars dataset, provided by R Cran (we can upload dataset by type
mtcars and then attach our dataset by
attach(mtcars)). A description of the data is available here.
If you obtained a different (correct) answer than those listed on the solutions page, please feel free to post your answer as a comment on that page.
Create a scatterplot of
mpg (x-axis) against
drat (y-axis) and add a label to the x-axis. Which of the following statements is correct:
plot(mpg,drat,xaxis="Miles per gallon")
plot(mpg,drat,xlab="Miles per gallon")
We just saw how to customize the label on the x-axis. For the next exercise:
a. Customize the y-axis label like we customized the x-axis in the previous exercise..
b. Produce a plot customizing x and y axis, range and colours. Choose a range for x axis from 0 to 40, for y axis from 0 to 7, red colour and highlighted points.
We have to add a title to our plot. What command do we have to type?
plot(mpg,drat,main="Miles vs Rar")
plot(mpg,drat,title="Miles vs Rar")
We just saw how to add labels, titles and custom details such as colours and the size of points. Now we will
have to construct our plot in different stages. Firstly we have to plot our data, secondly we will add axes, title and text.
a.Plot our data specifying that axes haven’t to be plotted.
b.Add axes, labels and text afterwards
Now we want to add a legend to our plot. Which statement is correct?
Customize our legend:
a.Use different types of symbols, colours, background colours and position.
b.Insert new variables to our plot and then customize the legend
Finally, we will build a plot using four continuous variables in two stages:
a. plot two variables at a time, eliminating axes. Introduce axes and labels afterwards.
b. Insert a legend using diffent colours and adifferent symbol for every variable. Put the legend in a top right position using x and y coordinates.
- Become a Top R Programmer Fast with our Individual Coaching Program
- Explore all our (>4000) R exercises
- Find an R course using our R Course Finder directory
- Subscribe to receive weekly updates and bonus sets by email
- Share with your friends and colleagues using the buttons below