In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
Today, the editor will share with you the relevant knowledge about how to use ggplot2 in R language. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article. Let's learn about it.
Ruler (Scale)
Drawing is mapping, whether it is mapping to different geometric objects, or mapping various graphic attributes.
# this section introduces rulers. After mapping graphic attributes, you can use rulers to control how these attributes are displayed
For example, coordinate scale may be logarithmically transformed through a ruler; for example, color attributes can also be changed through a ruler.
# take the scatter chart drawn in the data (Data) and Mapping section as an example, carry out the log10 transformation of the Y-axis coordinates, and then define the color as rainbow color.
Ggplot (small) + geom_point (aes (x=carat, y=price, shape=cut, colour=color)) + scale_y_log10 () + scale_colour_manual (values=rainbow (7))
Statistical transformation (Statistics)
The statistical transformation makes some calculation of the original data and then shows it on the graph, such as adding a regression line to the scatter graph.
# here will not be divided by color, cut, otherwise ggplot will do regression according to different classification variables, the picture will be very messy
# if we need to do this, we can use facets, which will be described later.
Ggplot (small, aes (x=carat, y=price)) + geom_point () + scale_y_log10 () + stat_smooth ()
# here, the parameters provided by aes are provided through ggplot, not to geom_point, because the parameters in ggplot are equivalent to global variables
# geom_point () and stat_smooth () both know the mapping of XBI y. If only provided to geom_point (), it is equivalent to a local variable.
# geom_point knows this mapping, but stat_smooth does not, and of course you also provide stat_smooth with the mapping of XMagery y.
# however, it is better to provide the shared mapping to ggplot.
Ggplot2 provides a variety of statistical transformation methods:
Stat_abline stat_contour stat_identity stat_summary
Stat_bin stat_density stat_qq stat_summary2d
Stat_bin2d stat_density2d stat_quantile stat_summary_hex
Stat_bindot stat_ecdf stat_smooth stat_unique
Stat_binhex stat_function stat_spoke stat_vline
Stat_boxplot stat_hline stat_sum stat_ydensity
Statistical # transformation is a very important function. We can write the function ourselves, do some calculation based on the original data, and show it on the graph. We can also change the default statistical parameters of geom_xxx function drawing through it.
For example, # replaces the median line of boxplot with an average to draw.
Coordinate system (Coordinante)
The coordinate system controls the coordinate axis, which can be transformed, such as XY axis flipping, Cartesian coordinate and polar coordinate transformation, to meet our various needs.
# Axis flipping is realized by coord_flip ()
Ggplot (small) + geom_bar (aes (x=cut, fill=cut)) + coord_flip ()
# conversion to polar coordinates can be achieved by coord_polar ():
Ggplot (small) + geom_bar (aes (x=factor (1), fill=cut)) + coord_polar (theta= "y")
# this is why the pie chart was not mentioned in the previous introduction to the common graphic drawing method. The pie chart is actually a column chart, only using polar coordinates. The height of the column chart corresponds to the Radian of the pie chart, and the pie chart is not recommended. Because the ability of human eyes to compare radians is not as high as that of the human eyes (bar chart)
# bull's-eye image:
Ggplot (small) + geom_bar (aes (x=factor (1), fill=cut) + coord_polar ()
# Wind Rose (windrose)
Ggplot (small) + geom_bar (aes (x=clarity, fill=cut)) + coord_polar ()
Layer (Layer)
The reason for the popularity of photoshop lies in the introduction of the concept of layers in PS 3.0. The best thing about ggplot is that it uses the + sign to overlay layers, which can be called a model of generic programming.
In the previous scatter chart, we have seen it, adding a regression line fitting layer.
# with the concept of layers, it is easier to use ggplot to draw pictures.
A good example of being a layer is that Batman logo,batman logo consists of six functions. In the following example, I draw the first function first, then add a layer to draw the second function, and repeat this process until all six functions are drawn.
Require (ggplot2)
F1data.frame (Xerox Magi Yaoyi)
D-3*sqrt (33) / 7,]
Return (d)
}
X1data.frame (x2=x2, y2=y2)
P2data.frame (x3=x3, y3=y3)
P3data.frame (x4mom x4jiny4)
P4data.frame (x5mom x5rem y5cm y5)
P5data.frame (x6mom x6ref y6mom y6)
P6
# below, take the bar chart + error chart commonly used in biology as an example to show the very flexible layers of ggplot2.
Normaldata.frame ("Normal", "Cancer"), mean=m, sd=s)
Dumped V
These are all the contents of the article "what is the use of ggplot2 in R language?" Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.