R语言之可视化(20)ggradar雷达图

2019-02-22 15:19:43 浏览数 (1)

ggradar是一个ggplot2函数,主要用于绘制数据分析的雷达图。 它基于Ricardo Bion的ggradar和Paul Williamson的CreateRadialPlot。ggradar允许使用ggplot2构建雷达图。 这个软件包基于Paul Williamson的代码,具有新的美学和与ggplot2 2.0的兼容性。 一些主要的函数:

代码语言:javascript复制
ggradar(plot.data, axis.labels = colnames(plot.data)[-1], grid.min = 0,
  grid.mid = 0.5, grid.max = 1, centre.y = grid.min - ((1/9) * (grid.max -
  grid.min)), plot.extent.x.sf = 1, plot.extent.y.sf = 1.2,
  x.centre.range = 0.02 * (grid.max - centre.y), label.centre.y = FALSE,
  grid.line.width = 0.5, gridline.min.linetype = "longdash",
  gridline.mid.linetype = "longdash", gridline.max.linetype = "longdash",
  gridline.min.colour = "grey", gridline.mid.colour = "#007A87",
  gridline.max.colour = "grey", grid.label.size = 7,
  gridline.label.offset = -0.1 * (grid.max - centre.y),
  label.gridline.min = TRUE, axis.label.offset = 1.15,
  axis.label.size = 8, axis.line.colour = "grey", group.line.width = 1.5,
  group.point.size = 6, background.circle.colour = "#D7D6D1",
  background.circle.transparency = 0.2, plot.legend = if (nrow(plot.data) >
  1) TRUE else FALSE, legend.title = "", legend.text.size = grid.label.size)

示例:

代码语言:javascript复制
setwd("D:\train")
devtools::install_github("ricardo-bion/ggradar", 
                         dependencies=TRUE)
library(ggradar)
suppressPackageStartupMessages(library(dplyr))
library(scales)
library(tibble)
mtcars %>%
  rownames_to_column( var = "group" ) %>%
  mutate_at(vars(-group),funs(rescale)) %>%
  tail(4) %>% select(1:10) -> mtcars_radar
ggradar(mtcars_radar) 

0 人点赞