library(purrr)
library(dplyr)
##
## 载入程辑包:'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(tidyr)
library(geomtextpath)
## 载入需要的程辑包:ggplot2
df <- iris %>% select(-Species) %>% map_df(max) %>% pivot_longer(everything())
df
## # A tibble: 4 x 2
## name value
## <chr> <dbl>
## 1 Sepal.Length 7.9
## 2 Sepal.Width 4.4
## 3 Petal.Length 6.9
## 4 Petal.Width 2.5
coord_radar <- function (theta = "x", start = - pi / 2, direction = 1) {
theta <- match.arg(theta, c("x", "y"))
r <- if (theta == "x") "y" else "x"
ggproto(
"CordRadar", CoordPolar, theta = theta, r = r, start = start,
direction = sign(direction),
is_linear = function(coord) TRUE)
}
df <- df %>%
mutate(
rnk = rank(-value),
face = if_else(rnk < 4, "bold", "plain"),
name = factor(name, levels = unique(name)))
df
## # A tibble: 4 x 4
## name value rnk face
## <fct> <dbl> <dbl> <chr>
## 1 Sepal.Length 7.9 1 bold
## 2 Sepal.Width 4.4 3 bold
## 3 Petal.Length 6.9 2 bold
## 4 Petal.Width 2.5 4 plain
library(ggplot2)
ggplot(df, aes(name, value, group = 1)) +
geom_polygon(fill = "red", colour = "red", alpha = 0.4) +
geom_point(colour = "red") +
coord_radar() +
ylim(0, 10) +
theme(axis.text.x = element_text(face = df$face))
## Warning: Vectorized input to `element_text()` is not officially supported.
## Results may be unexpected or may change in future versions of ggplot2.

ggplot(df, aes(name, value, group = 1)) +
geom_polygon(fill = "red", colour = "red", alpha = 0.4) +
geom_point(colour = "red") +
coord_polar() +
ylim(0, 10) +
theme(axis.text.x = element_text(face = df$face))
## Warning: Vectorized input to `element_text()` is not officially supported.
## Results may be unexpected or may change in future versions of ggplot2.

ggplot(df, aes(name, value, group = 1)) +
geom_polygon(fill = "red", colour = "red", alpha = 0.4) +
geom_point(colour = "red") +
coord_curvedpolar() +
ylim(0, 10) +
theme(axis.text.x = element_text(face = df$face))
## Warning: Vectorized input to `element_text()` is not officially supported.
## Results may be unexpected or may change in future versions of ggplot2.

##############https://stackoverflow.com/questions/62462681/ggradar-highlight-top-values-in-radar