简体   繁体   中英

What is this type of graph called and how do I create it in R

I have data and I need to reproduce a graph like this. I'm not sure what this type of plot is called, thus I also don't know how to plot it in R. Any help is appreciated.

要重现的图表

I don't know what it's called, but here's a function to produce one:

library(ggplot2)

quadrant_plot <- function(component, values, 
                          fills = c("#919191", "#686868", "#434343", "#ededed"))
{
  df <- data.frame(component  = factor(component, levels = component),
                   xvalue     = c(values[1:2], -values[3:4]),
                   yvalue     = c(values[1], -values[2:3], values[4]),
                   xmin       = c(0, 0, -Inf, -Inf),
                   xmax       = c(Inf, Inf, 0, 0),
                   ymin       = c(0, -Inf, -Inf, 0),
                   ymax       = c(Inf, 0, 0, Inf),
                   textx      = c(50, 50, -50, -50),
                   texty      = c(50, -50, -50, 50),
                   labelx     = c(95, 95, -95, -95),
                   labely     = c(95, -95, -95, 95),
                   hjust      = c(1, 1, 0, 0))

  ggplot(df, aes(xvalue, yvalue)) +
    geom_rect(aes(xmin = xmin, xmax = xmax, 
                  ymin = ymin, ymax = ymax, fill = component)) +
    geom_point() +
    geom_polygon(fill = NA, color = "black", size = 1) +
    geom_text(aes(x = textx, y = texty, label = abs(xvalue))) +
    geom_text(aes(x = labelx, y = labely, label = component, hjust = hjust),
              size = 6) +
    geom_hline(aes(yintercept = 0), size = 1) +
    geom_vline(aes(xintercept = 0), size = 1) +
    scale_fill_manual(values = fills, guide = guide_none()) +
    lims(x = c(-100, 100), y = c(-100, 100)) +
    coord_equal() +
    theme_void()
}

So you can do:

quadrant_plot(component = c("Adhocracy", "Hierarchy", "Market", "Clan"), 
              values = c(18.4, 22.9, 32.6, 26.5))

在此处输入图像描述

Or if you want to change the input and the colours you can do

quadrant_plot(component = c("Optimism", "Insight", "Skill", "Luck"), 
              values = c(35, 15, 12, 31),
              fills = c("gold", "deepskyblue4", "orange", "lightblue"))

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM