0
0
R Programmingprogramming~10 mins

Legend control in R Programming - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to add a legend to the plot.

R Programming
plot(x, y, type = 'l')
legend('topright', legend = [1], col = 'blue', lty = 1)
Drag options to blanks, or click blank then click option'
Ac('Data Line')
B'Data Line'
CData Line
D['Data Line']
Attempts:
3 left
💡 Hint
Common Mistakes
Using an unquoted string causes an error.
Using square brackets is not valid in R for vectors.
2fill in blank
medium

Complete the code to set the legend title.

R Programming
plot(x, y, type = 'l')
legend('topright', legend = c('Data'), title = [1], col = 'red', lty = 1)
Drag options to blanks, or click blank then click option'
Ac('Data Title')
Bc(Data Title)
C'Data Title'
DData Title
Attempts:
3 left
💡 Hint
Common Mistakes
Not using quotes causes an error.
Using c() creates a vector, but title expects a single string.
3fill in blank
hard

Fix the error in the legend position argument.

R Programming
plot(x, y, type = 'l')
legend([1], legend = c('Line'), col = 'green', lty = 1)
Drag options to blanks, or click blank then click option'
A'topright'
Btop right
Ctopright
Drighttop
Attempts:
3 left
💡 Hint
Common Mistakes
Using unquoted position names causes errors.
Using invalid position names causes the legend not to appear.
4fill in blank
hard

Fill both blanks to create a legend with two items and different colors.

R Programming
plot(x, y, type = 'l')
legend('bottomleft', legend = [1], col = [2], lty = 1)
Drag options to blanks, or click blank then click option'
Ac('Line1', 'Line2')
Bc('Line1')
Cc('red', 'blue')
Dc('green', 'yellow')
Attempts:
3 left
💡 Hint
Common Mistakes
Using only one label or one color causes mismatch errors.
Not using c() creates invalid arguments.
5fill in blank
hard

Fill all three blanks to customize the legend with line types and a title.

R Programming
plot(x, y, type = 'l')
legend('top', legend = [1], col = [2], lty = [3], title = 'Legend')
Drag options to blanks, or click blank then click option'
Ac('A', 'B')
Bc('black', 'orange')
Cc(1, 2)
Dc('red', 'blue')
Attempts:
3 left
💡 Hint
Common Mistakes
Mismatched vector lengths cause errors.
Using color names not recognized by R causes warnings.