In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "the introduction and beautification method of density curve in R language visualization". In daily operation, it is believed that many people have doubts about the introduction and beautification method of density curve in R language visualization. The editor consulted all kinds of data and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts of "introduction and beautification of density graph in R language visualization". Next, please follow the editor to study!
Today I would like to share with you about the density graph and its beautification skills!
Density curve may not be used much, but it is not mysterious, its function is the same as histogram, it is used to express the distribution pattern of continuous numerical variables.
The case still uses the previous data set about diamonds.
The layer function used in the density curve is geom_density (), and the location type of the position parameter in the function is the same as the histogram and bar chart we talked about earlier.
Ggplot (diamonds,aes (x=price)) + geom_density ()
The line color is controlled by colour parameters (be sure to remember the difference between colour and fill color filling parameters. Colour controls line, point color and fill control area color, so use colour parameter in scatter chart, curve and line chart, and use fill parameter in area chart and column chart)
Ggplot (diamonds,aes (x=price)) + geom_density (colour= "steelblue")
Of course, classification variables are also allowed in the function of the density curve:
Ggplot (diamonds,aes (XeropriceMagna colourful stories)) + geom_density ()
Colour control points, line colors, and fill control area colors are mentioned above, but the density curve is an alternative. If you take a closer look at the figure above, you will find that it is different from the line chart, because each density curve is a closed curve, so it is allowed to fill the closed area with the fill parameter:
Ggplot (diamonds,aes (XeropriceLegacy)) + geom_density ()
You will find that except for the filled color inside the density curve, the overall shape is the same as using the colour parameter to fill the line color.
Now let's recall that when we deal with position when we deal with the histogram in the previous section, position has four main parameters that we commonly use:
Identity (no transformation), stack (stacking), dodge (clustered), fill (percentage stacking)
In fact, as long as the collection layer objects at the beginning of geom are applicable to these parameters, then with our analysis, the default parameter of the above density curve should be identity, let's verify our conjecture.
Ggplot (diamonds,aes) + geom_density (position= "identity")
Ggplot (diamonds,aes (Xeroprice)) + geom_density (position= "identity")
As we expected, the default density curve with classified variables does use the default identity parameter.
So let's try the effect of the density curve in the case of several other parameters:
Stacking: (position= "stack")
Ggplot (diamonds,aes (Xeroprice)) + geom_density (position= "stack")
Ggplot (diamonds,aes (Xeroprice)) + geom_density (position= "stack")
Stacking: (position= "dodge") # in the case of density curve, it is inappropriate to make a cluster effect, but I still want to see the effect.
Ggplot (diamonds,aes (Xeroprice)) + geom_density (width = 1000))
Ggplot (diamonds,aes (Xeroprice)) + geom_density (position=position_dodge (width = 1000))
You can see that after using the dodge parameter, the R language will suggest that the X axis in the density curve must be data with no repetition interval scale, and the probability density curve here cannot meet this requirement:
So the last position parameter is position=fill (stacking percentage)
Ggplot (diamonds,aes (Xeroprice)) + geom_density (position= "fill")
Ggplot (diamonds,aes (Xeroprice)) + geom_density (position= "fill")
On the faceted expression of probability density curve:
Ggplot (diamonds,aes (xylene fill)) + geom_density (position= "fill") + facet_grid (. ~ clarity)
Ggplot (diamonds,aes (Xeroprice fill)) + geom_density (position= "fill") + facet_grid (. ~ clarity)
Through the graphic effect, we can see that the facet expression of the probability density curve has no practical significance, because there is only one category in a single sequence, then its proportion is naturally 100%.
By applying the theme and color matching template, we can beautify the density curve properly:
Ggplot (diamonds,aes (Xeroprice)) + geom_density (position= "fill") + theme_wsj () + scale_fill_wsj () + guides (fill=guide_legend (title=NULL))
Ggplot (diamonds,aes (Xeroprice)) + geom_density (position= "fill") + theme_wsj () + scale_colour_wsj () + guides (colour=guide_legend (title=NULL))
Ggplot (diamonds,aes (Xeroprice)) + geom_density (position= "stack") + theme_wsj () + scale_fill_wsj () + guides (fill=guide_legend (title=NULL))
Ggplot (diamonds,aes (Xeroprice)) + geom_density (position= "stack") + theme_wsj () + scale_colour_wsj () + guides (colour=guide_legend (title=NULL))
Because the upper limit of the number of colors in the applied color matching template is 6, and we have 8 categories of classification variables, the bar color and fill color of the last two categories have been changed to the default.
At this point, the study of "introduction and beautification of density graph in R language visualization" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.