In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "what are the types of polar coordinate transformation and derivative charts in R language visualization". The content of the explanation in this article is simple and clear, and it is easy to learn and understand. let's study and learn "what are the types of polar coordinate transformation and derivative charts in R language visualization?"
Today's article will be a bit messy because it will talk about a large class of graphical effects that can only be rendered through polar support in the ggplot function.
The graphic philosophy behind ggplot's drawing does not give room for pie charts (as well as derived radial chart types such as circles and roses) to exist (mainly because of the personal aesthetics of the developers of the package, comparing antisensory secondary axes and repetitive layer functions with the same functional types, so it would rather develop faceted layer principles than add secondary axes. Do not want to develop a pie chart function with the same function for the chart form that can be expressed by the original column chart.
But coincidentally, among the three common coordinate forms, polar coordinate transformation can easily transform the common column chart (bar chart) and stacked column chart into pie chart, rose chart, circle chart and so on (I don't know whether it is intentional or accidental coincidence).
The pie chart needs to be transformed with the help of a column chart and polar coordinates:
Ggplot (diamonds,aes (x=factor (1), fill=cut) + geom_bar ()
When a factor variable is used as the horizontal axis and filled with a classification variable, the column chart becomes a single stacked column chart.
Next, we add polar coordinates through the above function (notice how the setting of polar coordinates affects the final chart form)
Ggplot (diamonds,aes (x=factor (1), fill=cut)) + geom_bar () + coord_polar (theta = "y")
Ggplot (diamonds,aes (x=factor (1), fill=cut)) + geom_bar () + coord_polar (theta = "x")
Ggplot (diamonds,aes (x=factor (1), fill=cut) + geom_bar () + coord_polar ()
From the chart made and the parameters in the polar function, we can see that when the parameter is specified as x, the x axis of the final column chart will be designated as the x axis (circumference) of the polar coordinates, while the y axis of the column chart will become the y axis (radius) of the polar coordinates. When the y axis is specified, the y axis of the column chart is the x axis (circumference) that becomes the polar coordinate, and the x axis of the column chart becomes the y axis (radius) of the polar coordinate.
At the same time, in polar coordinates, the radius of the pie chart is determined by the width of the column chart, and there is a blank in the center of the above chart. If we define the width of the column chart as 1, it will become a positive circle.
Ggplot (diamonds,aes (x=factor (1), fill=cut)) + geom_bar (width=1) + coord_polar (theta = "y")
The other elements in the figure are controlled in the same way as the usual column chart:
Remove the axis scale label of the polar axis, remove the two axis titles, and change the color match:
Ggplot (diamonds,aes (x=factor (1), fill=cut) + geom_bar (width=1) + coord_polar (theta = "y", start=0) + theme (panel.grid = element_blank (), panel.background = element_blank (), axis.text = element_blank (), axis.ticks = element_blank (), axis.title = element_blank ()) + scale_fill_brewer (palette= "Blues") + guides (fill=guide_legend (reverse=TRUE,title=NULL))
When there are multiple sequences:
Ggplot (diamonds,aes (cut)) + geom_bar (width=1)
The effect of circle chart and bar chart can be realized through polar coordinate transformation.
Ggplot (diamonds,aes (cut)) + geom_bar (width=1,fill= "steelblue", colour= "white") + coord_polar (theta = "y", start=0) + theme (panel.grid = element_blank (), panel.background = element_blank (), axis.text.x = element_blank (), axis.title = element_blank ())
By changing the polar axis parameter settings, you can simulate the Nightingale rose effect:
Ggplot (diamonds,aes (cut)) + geom_bar (width=0.95,fill= "# 3182BD") + coord_polar (theta = "x", start=0) + theme (panel.grid = element_blank (), panel.background = element_blank (), axis.text.y = element_blank (), axis.ticks= element_blank (), axis.title = element_blank ()) + ylim (c (- 3000 ~ 22500))
Of course, if you add a classification sequence (that is, a stacked column chart) to the original column chart data, you can make more complex circles and stacked roses in the above way.
Ggplot (diamonds,aes) + geom_bar (width=0.95,colour= "white") + coord_polar (theta = "y", start=0) + theme (panel.grid = element_blank (), panel.background = element_blank (), axis.text.x = element_blank (), axis.title = element_blank ()) + scale_fill_brewer (palette= "Blues") + guides (fill=guide_legend (reverse=TRUE,title=NULL))
Ggplot (diamonds,aes) + geom_bar (width=0.95,colour= "white") + coord_polar (theta = "x", start=0) + theme (axis.text.y = element_blank (), axis.title = element_blank ()) + scale_fill_brewer (palette= "Blues") + guides (fill=guide_legend (reverse=TRUE,title=NULL)) + ylim (c (- 2000)) + theme_bw ()
Try to solve the multi-sequence problem with facets:
Ggplot (diamonds,aes) + geom_bar (width=0.95,colour= "white") + coord_polar (theta = "x", start=0) + theme (axis.text.y = element_blank (), axis.title = element_blank ()) + scale_fill_brewer (palette= "Blues") + guides (fill=guide_legend (reverse=TRUE,title=NULL)) + ylim (c (- 2000,000,000,000) + theme_bw () + facet_grid (. ~ cut)
Thank you for your reading, the above is the content of "what are the polar coordinate transformation and derivative chart types in R language visualization?" after the study of this article, I believe you have a deeper understanding of the polar coordinate transformation and derivative chart types in R language visualization, and the specific use still needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.