A graph solves various problems of the R language drawing legend _r

Source: Internet
Author: User
A picture solves various problems of the R language drawing legend
2016-11-01

With the R drawing of the small partners have wood has such a feeling, "the command to write a very complete, the operation did not complain, the legend can hide where." "The picture is very beautiful, how always the legend is not coordinated." "Ah ~ ~ Ah, crazy, the legend covers the key points." "How to make the legend point to which station." "How long is the legend?"


Vomit the trough to be tired, better grasps several legends (Legend) The soft Rib, uses the R language drawing more.


Legend (x, y = NULL, legend, fill = Null,col =, Bty = "O", Xjust = 0, Yjust = 1, x.intersp = 1, y.intersp =1, adj = C (0, 0.5 ), text.width = null,xpd=true)


Legend positioning


1. If the legend is drawn outside the drawing area, the space for drawing legend must be retained in advance. such as Par (Mai=c (2,0.5,0.5,0.5)), the legend is drawn below, so stay 2 and the remaining 3 directions are 0.5.

2. The legend is drawn outside the mapping area, you must set the parameter xpd=true, otherwise the command will not be correct, because the default xpd=f.

3. The legend position is decided by x,y. Legend the default coordinates are the coordinates of the upper-left corner (because the xjust=0,yjust=1 is set), so you can adjust them by xjust,yjust. Xjust=1,yjust=0, which is the lower right corner coordinate.


Legend layout


1. If the number of legends is too large, set multiple columns (ncol=), such as ncol=4, into 4 columns.

2. If the legend does not have a border, set bty= "n" and "O" as a border.

3. The position of the icon and the text can be regulated by X.INTERSP, Y.INTERSP, adj,text.width, etc.

X (y). INTERSP refers to the absolute distance between the icon and the Text Adj refers to the relative distance text between the icon and the text.

Width refers to the size of the icon and the text as a whole.


Here is a picture combined with a statement to show you the key parameters of the R drawing legend.



Command 1

Sets the boundary space of the drawing parameter mai=c (bottom, left, top, right).

Command 2

Draw a column chart. Command 3

Select the coordinates of the lower-left and upper-right corners of the drawing area. Command 4

Normal drawing, setting xpd=t. Xinch (), Yinch (), respectively, representing the distance along the x-axis, y-axis, calculated by absolute distance, or by the order of magnitude of the axes. Fill=t, which is the display icon (the default is rectangular fill color). Fill=f you can set the PCH, select the icon type. Command 5

The closer you set the Adj=0.6,adj to 0, the farther away the icon is from the text.

This parameter acts on the text and the icon does not move. Command 6

Set x.intersp=0.6, closer to 0, the icon and the absolute distance of the text closer. With one side as the standard, the icon text is moved. Command 7

Sets the text.width=1.4 to indicate the width of the icon and the text as a whole. This parameter can be adjusted when the text is too long. Command 8

Text.width and X.INTERSP combined to use, the best effect. Command 9

Set ncol=2, divided into two columns.

R language Drawing 004-legend () parameter detailed

Legend (x, y = null, legend, fill = null, col = par ("col"),

border = "Black", Lty, LWD, PCH,

Angle = density = NULL, bty = "O", bg = par ("bg"),

BOX.LWD = par ("LWD"), box.lty = par ("lty"), Box.col = par ("FG"),

pt.bg = NA, CeX = 1, Pt.cex = CeX, PT.LWD = LWD,

Xjust = 0, Yjust = 1, x.intersp = 1, y.intersp = 1,

Adj = C (0, 0.5), text.width = NULL, Text.col = par ("col"),

Text.font = NULL, merge = Do.lines && has.pch, trace = FALSE,

Plot = TRUE, Ncol = 1, Horiz = FALSE, title = NULL,

Inset = 0, xpd, Title.col = text.col, Title.adj = 0.5,

Seg.len = 2)

X, y

X,y is used to locate the legend, but also use the single word "bottomright", "Bottom", "Bottomleft", "left", "TopLeft", "Top", "TopRight", "right" and "center"

Legend

Vector of characters or expressions

Fill

Fill with a specific color

Col

The color of dots or lines appearing in the legend

Border

When fill = parameter exists, the border of the fill color

Lty, LWD

The type and width of the centerline of the legend

Pch

Type of point

Angle

The angle of the shadow

Density

The density of the shadow line

Bty

The legend box is drawn, O is drawn, the default is n does not draw

Bg

The background color of the legend when Bty!= "n"

Box.lty, BOX.LWD, Box.col

Bty = "O", the type of the legend box, Box.lty determines whether it is dashed, BOX.LWD determines the thick line, Box.col determines the color

Pt.bg

The background color of the point

CeX

Character size

Pt.cex

The size of the point

Pt.lwd

The line width of the edge of the point

X.intersp

The horizontal distance of the text from the picture in the legend

Y.intersp

The vertical distance from the picture from the text in the legend

Adj

The relative position of the font in the legend

Text.width

The width of the legend font

Text.col

Color of Legend Font

Text.font

Legend Font

Merge

Logical, if true, merges dots and lines, but does not populate legend boxes, defaults to TRUE

Trace

Logical If True displays legend information.

Plot

Logical. If false does not draw a legend

Ncol

Number of columns categorized in the legend

Horiz

Logical If TRUE, position legend horizontally

Title

Add a title to the legend

Inset

When the legend set the position with the keyword, inset = fraction, you can set its relative position

Xpd

Xpd=false, that is, not allowed in the drawing area outside the drawing, to true, and par () parameters with the use.

Title.col

Title Color

Title.adj

The relative position of the legend title, 0.5 is the default, in the middle. 0 leftmost, 1 is the most right.

Seg.len

Line length of lty and LWD, length unit is character width
Hello R Users,

I have some troubles to modify the ' per default ' legend in the
Scatterplot.matrix using the car package. This is my code:

--------------------------------------------------------------------
Scatterplot.matrix (~ a + B + C,
Groups=treatment,
By.groups=f,
Data=newfile3,
Smooth=t,
Pch=c (16,4),
cex=1.3,
Labels=label,
cex.labels=1.3,
font.labels=2,
Col=c ("Black", "dark grey", "black" and "black"),
Legend.plot=t,
)
Legend ("TopRight", C ("fenced", "unefenced"), fill=null,bty= "O", cex=3)
--------------------------------------------------------------------

In the I dataset, the variable "treatment" contains two levels that are "N"
and "Y" (for No and Yes) and appear in I ' per default ' legend that is located
In the Buttomright's my 3x3 scatterplot. I would like to replace N by a list
of character: "Unfenced" and Y by "fenced", as as is moving the legend in
Another place in my graphic ... is someone know
Scatterplot?

Thank ' s

Julien

--
Julien Beguin
Etudiant-chercheur au Doctorat
Laboratoire d ' Analyse quantitative des paysages, local 2113
Facultéde Foresterie et de géomatique
Universitélaval
2405 rue de la Terrasse, g1v 0a6 Québec (Qc)
Tel: (418) 656-2131 poste 2620

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.