# R language ggplot2 to draw ring chart radar chart / star chart / polar chart / radial chart polar chart visual analysis of vehicle performance data

Time：2022-4-30

Beautiful circle chart. I’m not sure if there is any additional benefit to the data analyst itself, but if it can attract the attention of decision makers, it is additional value to me.

However, with Coord\_ Occasionally found in coggar\_ Radar () can be difficult to build. The two main problems I found are that the change of polar coordinates will bend your path into a circle, and the radar can’t communicate with geom_ Bin is used in combination to fill the background.

That’s why I usually use it in Cartesian coordinate system. More like a mathematical solution. Map your data and drawing requirements so that they eventually become a circle. As an added benefit, I also found that it builds / loads faster. It’s important to me because I let them interact in shiny apps.

I used mtcars data in my example. The figure shows 12 cars in the collection:

• Cylinder in background. 4. Light, medium and dark colors for cylinders 6 and 8.
• Mark the miles per gallon of each car in blue.

I use the first 12 cars and want a column with row names.

``add_rownames\[1:12,\]``

# Draw data mapping

To map the values of any column I want to draw, I create a function. It basically checks how many variables you want to plot and plots sinusoids for X and Y values.

``````  lev <- levels
num <- length

dir <- rep
dir_ <- map_dbl
interp
data <- mutate_``````

Store mapping data to map mpg variables for all tags.

``````#Data point
rotate_data``````

I wanted to show the plot range data, so I forged a series of qseC data. Basically, you generate a data frame with multiple values (rows) for qseC on each vehicle (label).

``````#Make up some range data
bind_rows
rotate_data``````

Use polygon to draw the range, and use path and point to draw the mpg value.

``````lim <- max
#Use your own data and aesthetics to draw the pattern of each layer
ggplot() +
geom_polygon+
geom_point+
theme+
coord_equal``````

I guess the desired grid is made up of radially outward lines with circles. Create x, xend, y, and yend data points to draw segments between them.

``````r <- data_frame %>%
mutate
r\$xed <- 0
r\$yed <- 0``````
``````#Use your own data and aesthetics to draw the pattern of each layer

ggplot() +
geom_segment +
geom_polygon+
geom_point +
ylim + xlim +
theme+
coord_equal``````

# label

Add a text label to the variable you rotate.

``label <- levels``
``````ggplot() +
geom_segment +
geom_polygon +
geom_path +
geom_point +
geom_text+
theme +
coord_equal``````

# Draw a circle

To draw a circle, I’ll use a circle with a fill option.

``````t <- seq
d <- data.frame
If (fed = = true) {## add a point in the center to fill the whole "cake"
d <- rbind
}
return(d)``````

# Grid circles and labels

Circular gridlines are built by calling circle multiple times and storing all points in the data frame.

``````cregrd <- data_frame
crld <- cili %>%
mutate

poties <- bind_rows
loics\$lv <- as.factor``````

Circular labels can be added in many ways. But in order to simply set all axis text and axis labels to blank, I built a data box that can be drawn using text.

``````c <- data_frame
cl <- cl\[x <= max,\]``````
``````ggplot() +
geom_segment +
geom_path+
geom_text+
geom_polygon +
geom_point +
geom_text + xlim +
theme+
coord_equal``````

# background

With circle, you can also easily build a circular part, which you can fill with the filled = true parameter. There is a slight – 1 / num offset to align the section correctly. Here, you propose the factor variable you want to color. Of course, you can also change the code to change the “height” of each bar according to the variable.

``````num      <- length
levels   <- rev
tart    <- seq

bg  <- data_frame
mutate

bgdta <- tdf
bgdta\$lv <- as.factor``````

# Central circle

Not much detail, but you may want to add some center circles.

``````lm <- max
ggplot() +
geom_polygon+
geom_segment +
geom_path+
geom_text +
geom_polygon+
geom_polygon+
geom_path +
geom_point +
geom_text +
ylim + xlim +
theme +
coord_equal``````

Most popular insights

## Network counting experiment I Division VLAN

Experiment 1  vlanCreation and division of 1、 Experiment purpose: 1. Understand the working principle of VLAN; 2. Learn the method of dividing VLANs based on ports; 3. Understand the communication between the same VLANs across switches; 4. Further learn the configuration commands of switch ports. 2、 Experimental principle: VLAN (virtual local area network), that is, […]