当前位置:网站首页>[data analysis and visualization] key points of data drawing 8- use of circular bar chart

[data analysis and visualization] key points of data drawing 8- use of circular bar chart

2022-06-13 02:34:00 The winter holiday of falling marks

Key points of data drawing 8- Use of circular bar chart

Circular bar chart RADIAL BAR CHARTS A bar graph drawn in polar coordinates rather than in a Cartesian plane ,RADIAL BAR CHARTS There is no prescribed Chinese translation , Some people translate it as a circular bar chart , Some people translate it as a radial bar graph .

Drawing examples

The following figure shows 2017 Before a certain commodity 6 The number of exports from large countries .

#  Import library 
library(tidyverse)
library(hrbrthemes)

#  Load data 
data <- read.table("https://raw.githubusercontent.com/holtzy/data_to_viz/master/Example_dataset/7_OneCatOneNum.csv", header=TRUE, sep=",")
head(data)
nrow(data)
A data.frame: 6 × 2
CountryValue
<fct><int>
1United States 12394
2Russia 6148
3Germany (FRG) 1653
4France 2162
5United Kingdom 1214
6China 1131

51

#  Delete null data 
data <-filter(data,!is.na(Value))
#  Sort data from small to large 
data <-arrange(data,Value)
#  Extract tail 6 Bit data 
data <-tail(data,6)
#  Create data tables 
data <-mutate(data,Country=factor(Country, Country))
head(data)
nrow(data)
A data.frame: 6 × 2
CountryValue
<fct><int>
33United Kingdom 1214
34Israel 1263
35Germany (FRG) 1653
36France 2162
37Russia 6148
38United States 12394

6

#  mapping 
ggplot(data, aes(x=Country, y=Value) ) +
geom_bar(fill="#69b3a2", stat="identity") +
geom_text(hjust = 1, size = 3, aes( y = 0, label = paste(Country," "))) +
theme(
  panel.grid.minor.y = element_blank(),
  panel.grid.major.y = element_blank(),
  legend.position="none",
  axis.text = element_blank()
) +
xlab("") +
ylab("") +
#  Using polar coordinates 
coord_polar(theta = "y") +
ylim(0,15000) 

png

The obvious advantage of this graphic is that it is very compelling . however , Because the bar graph is drawn on different radial points of the polar axis , So they have different radii , Cannot compare by length . There are other problems with this diagram , In the absence of Y Axis . The specific reasons are shown in the figure below . In the following figure, if you want to know the relationship of bar values in the first circular bar graph , It is generally judged by the length of the bar . But when the strip is stretched into arc length, it will deform , The comparison result is shown in the second picture , However, the actual results of various bar numerical relationships are the third graph .

resolvent

If you pay attention to the display of data volume , We can add value labels to the circular bar chart or use the bar chart , Lollipop chart .

Add value labels

#  mapping 
ggplot(data, aes(x=Country, y=Value) ) +
geom_bar(fill="#69b3a2", stat="identity") +
geom_text(hjust = 1, size = 3, aes( y = 0, label = paste(Country," ",Value," "))) +
theme(
  panel.grid.minor.y = element_blank(),
  panel.grid.major.y = element_blank(),
  legend.position="none",
  axis.text = element_blank()
) +
xlab("") +
ylab("") +
#  Using polar coordinates 
coord_polar(theta = "y") +
ylim(0,15000) 

png

Lollipop chart

ggplot(data, aes(x=Country, y=Value) ) +
#  Draw line 
geom_segment( aes(x=Country ,xend=Country, y=0, yend=Value), color="grey") +
geom_point(size=3, color="#69b3a2") +
#  Flip axis 
coord_flip() +
theme(
  panel.grid.minor.y = element_blank(),
  panel.grid.major.y = element_blank(),
  legend.position="none"
) +
xlab("")

png

Reference resources

原网站

版权声明
本文为[The winter holiday of falling marks]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202280540284287.html