Regarding geom_segment (aes (x = x0, y = y0, xend = x1, yend = y1)) in ggplot2

Ggplot2 has a usage that looks like this:

geom_segment(aes(x=x0,y=y0,xend=x1,yend=y1)) 

What does aes(x=x0,y=y0,xend=x1,yend=y1) mean aes(x=x0,y=y0,xend=x1,yend=y1) ?

I checked the ggplot2 manual but does not explain these parameters in detail. Thanks.

+4
source share
1 answer

The aes function is used to map variables (e.g. columns) in data.frame to the visual properties of the graph. A graph consists of one or more geometries, for example. geom_point for points or geom_polygon for polygons. Each of these geometries has different properties, as well as aesthetics. A simple example is point geometry ( geom_point ). This geometry has the following aesthetics (from the man page, see "Geom_point"):

 Aesthetic Default x required y required shape 16 colour black size 2 fill NA alpha 1 

It can be seen from this list that point geometry has two required aesthetics: the x-coordinate of a point ( x ) and the y-coordinate of a point ( y ). Additional aesthetics have default values, but can also be bound to a column in a dataset to make them a variable. For example, binding size to a column in the data changes the size of the point in accordance with this variable.

To answer your question. Segment geometry is used to draw line segments. The aesthetics needed for this are the starting point for the line segment ( x and y ) and the ending point for the line ( xend and yend ). So the line:

 aes(x=x0,y=y0,xend=x1,yend=y1) 

says that we want ggplot to draw line segments for each row in data.frame, where the line is drawn from the coordinates ( x , y ) in ( xend , yend ). Hope this makes things easier.

+4
source

Source: https://habr.com/ru/post/1385226/


All Articles