R language ggplot2 drawing torus radar chart / star chart / polar chart / radial chart polar chart visual analysis of vehicle performance data

Time:2022-6-20

Original link:http://tecdat.cn/?p=24896

R language ggplot2 drawing torus radar chart / star chart / polar chart / radial chart polar chart visual analysis of vehicle performance data

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

However, with Coord\_ Polar() or coord in ggplot2 found occasionally\_ 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 conjunction to fill the background.

This is why I usually use Cartesian coordinates. More like a mathematical solution. Map your data and drawing requirements so that they eventually become circles. As an added benefit, I also found it to be faster to build / load. It’s important to me because I let them interact in shiny apps.

I used mtcars data in my example. The figure shows the 12 vehicles 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.

This article is a step-by-step demonstration of how to add the required elements to a circular diagram. Many things can be improved. Please feel free to comment.

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

add_rownames\[1:12,\]

Draw data mapping

To map the values of any column I want to plot, 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 labels.

#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 (tag).

#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
#Draw the pattern of each layer with your own data and aesthetics
ggplot() + 
  geom_polygon+
  geom_point+
  theme+ 
  coord_equal

R language ggplot2 drawing torus radar chart / star chart / polar chart / radial chart polar chart visual analysis of vehicle performance data

Radial line

I guess the desired grid is made up of radial 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
#Draw the pattern of each layer with your own data and aesthetics

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

R language ggplot2 drawing torus radar chart / star chart / polar chart / radial chart polar chart visual analysis of vehicle performance data

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

R language ggplot2 drawing torus radar chart / star chart / polar chart / radial chart polar chart visual analysis of vehicle performance data

Draw a circle

To draw a circle, I will 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 "pie"
    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 a number of ways. But 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

R language ggplot2 drawing torus radar chart / star chart / polar chart / radial chart polar chart visual analysis of vehicle performance data

background

With circle, you can also easily build a circle section, which you can fill with the filled = true parameter. There is a little -1/num offset to make the part align 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 based on variables.

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

R language ggplot2 drawing torus radar chart / star chart / polar chart / radial chart polar chart visual analysis of vehicle performance data


R language ggplot2 drawing torus radar chart / star chart / polar chart / radial chart polar chart visual analysis of vehicle performance data

Most popular insights

1.R language dynamic graph visualization: how to create graphs with exquisite animation

2.Visual analysis of R language survival analysis

3.Python data visualization Seaborn iris data

4.Simulation and dynamic analysis of Bufeng injection experiment with R language

5.R language survival analysis data analysis visualization case

6.R language data visualization analysis case: exploring BRFSS data analysis

7.Dynamic visualization in R language: making animated GIF video graph of cumulative dynamic line graph of historical global average temperature

8.Principal component PCA and t-sne algorithms for dimensionality reduction and visual analysis of high-dimensional data in R language

9.Python theme LDA modeling and t-sne visualization

Recommended Today

3- build Hadoop ha

3- build Hadoop ha 0. change host name  hostnamectl set-hostname master hostnamectl set-hostname master2 hostnamectl set-hostname slave 1.ssh password free login (1) , generate secret key (group sending)  ssh-keygen (2) , configure hosts \, vi /etc/hosts\ 192.168.204.152 master 192.168.204.153 master2 192.168.204.154 slave\ (3) , add public key by appending (mass sending) First host: ssh-copy-id master yes000000 (enter the set password)Second host: ssh-copy-id master2 yes000000 (enter […]