The basic graph types
- Loading required package
- Description of the basic graph types
- Practice Examples
- Point map + Title
- + + The title bar of the "value" counts
- Line chart title +
- FIG area (in general, based on the diagram, the filled area under the line)
- FIG path (connection data in order of appearance)
- Scattergram containing label (label specified points are added)
- FIG color depth or level of FIG.
- Polygon drawing, i.e. the path the filled
Loading required package
library(effects)
library(ggplot2)
Description of the basic graph types
The following geometric objects are ggplot2 essential part of the graph. Each geometry object graphics can build their own independent, but can also be combined to build more complex geometry. These are basically geometric objects associated with a common pattern: When a web graphics using only geometric objects built, this figure tend to have a specific name.
These are two-dimensional geometric objects, so the x and y properties of two kinds of graphics are indispensable. At the same time, they can accept colour
and size
graphic attributes Further, filled geometric objects (bar, tiles ( tile
) and polygonal) may also be acceptable fill
graphical properties. Properties using dot shape pattern, line, and path receiving linetype
graphics attributes. These geometric objects can be used to display the raw data, summary data calculated separately and metadata.
-
geom_area()
FIG area for drawing (area plot), that is based on the normal line map, the pattern area is filled by the lower y-axis direction. For packet data, each group will be drawn sequentially stacked manner. -
geom_bar(stat="identity")
Draw a bar graph. We need to specifystat="identity"
, because the default statistics will be automatically converted to "value" to count (so this is essentially a one-dimensional geometric objects). The statistical data transformed identity will remain unchanged.
By default, the same position a plurality of bar will form sequentially stacked upwardly drawn. -
geom_line()
Draw a line chart. Graphics attributegroup
determines which observations are connected together;
Reference R setting ggplot2- visual language, mapping, packet, pattern matching properties and graphic objects
for more details.geom_path
Withgeom_line
similar, butgeom_path
the lines are connected in the order they appear in the data, instead of connecting from left to right. -
geom_point()
Draw a scatter plot. -
geom_polygon()
Drawing a polygon, i.e., the path after filling. Each row of data represents a polygon vertices. Before drawing the polygon apex coordinate data and the original data is often more convenient to merge. Follow-up content to the map data as an example to clarify this concept in detail. -
geom_text()
Tags can be added at the given point. It is the only one of these geometric objects require additional graphical properties: it needs to specifylabel
parameters. We can set an optional graphical propertieshjust
andvjust
to control the vertical and horizontal position of the text; Furthermore, graphical properties can be providedangle
to control the rotation of the text. You may be?geom_text
more to learn. -
geom_tile()
FIG color depth for drawing (image plot) or FIG horizontal (level plot). All tile (the tile) constitutes a plane slicing a rule and often will befill
mapped graphics attributes to another variable.
The following code draws more geometric objects, the results shown in FIG.
Practice Examples
The basic geometric objects using different drawing effect the same data.
Pattern names are from top to bottom: scatter plots, bar, line, area, the road map containing the label scattergram FIG color depth / level map and polygons FIG.
Observe bar, area, and FIG tile coordinate axis range: three geometric objects occupying the space outside the scope of the data itself, then the axes are automatically stretched.
df <- data.frame(
x = c(3, 1, 5),
y = c(2, 4, 6),
label = c("a","b","c")
)
p <- ggplot(df, aes(x, y)) + xlab(NULL) + ylab(NULL)
Point map + Title
p + geom_point() + labs(title = "geom_point")
+ + The title bar of the "value" counts
p + geom_bar(stat="identity") +
labs(title = "geom_bar(stat=\"identity\")")
Line chart title +
p + geom_line() + labs(title = "geom_line")
FIG area (in general, based on the diagram, the filled area under the line)
p + geom_area() + labs(title = "geom_area")
FIG path (connection data in order of appearance)
p + geom_path() + labs(title = "geom_path")
Scattergram containing label (label specified points are added)
p + geom_text(aes(label = label)) + labs(title = "geom_text")
FIG color depth or level of FIG.
p + geom_tile() + labs(title = "geom_tile")
Polygon drawing, i.e. the path the filled
p + geom_polygon() + labs(title = "geom_polygon")