如何解决这种类型的图称为什么,以及如何在R中创建它
我有数据,我需要复制这样的图形。我不确定这种绘图的类型是什么,因此我也不知道如何在R中进行绘图。
解决方法
我不知道它叫什么,但是这里有一个产生一个的函数:
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,-Inf,-Inf),xmax = c(Inf,Inf,0),ymin = c(0,ymax = c(Inf,Inf),textx = c(50,50,-50,-50),texty = c(50,50),labelx = c(95,95,-95,-95),labely = c(95,95),hjust = c(1,1,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()
}
因此您可以这样做:
quadrant_plot(component = c("Adhocracy","Hierarchy","Market","Clan"),values = c(18.4,22.9,32.6,26.5))
或者如果您想更改输入和颜色,可以
quadrant_plot(component = c("Optimism","Insight","Skill","Luck"),values = c(35,15,12,31),fills = c("gold","deepskyblue4","orange","lightblue"))
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。