是否可以在每个圆具有不同颜色的R中绘制雷达图? [英] Is it possible to draw a radar chart in R where each circle has a different colour?

查看:314
本文介绍了是否可以在每个圆具有不同颜色的R中绘制雷达图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用fsmb软件包,我创建了一个简单的雷达图. 这是一个可重现的示例:

Using the fsmb package I created a simple radar chart. Here is a reproducible example:

#install.packages("fmsb")
library(fmsb)
data <- data.frame(rbind(rep(8,14),
          rep(0,14),
          c(3,4,4,4,3,4,4,4,4,3,3,3,3,3)))
colnames(data) <- c("biologia", "chemia", "fizyka", "geografia", "historia", "informatyka", "język angielski", "język polski", "matematyka", "muzyka / historia muzyki", "plastyka / sztuka / historia sztuki", "sprawność fizyczna", "technika","wiedza o społeczeństwie" )

radarchart(data, 
       axistype=1 ,
       pcol=rgb(0.2,0.5,0.5,0.5), 
       pfcol=rgb(0.2,0.5,0.5,0.5),
       plwd=4,
       cglcol="grey", 
       cglty=1, 
       axislabcol="grey", 
       caxislabels=seq(0,8,2), cglwd=0.8,
       vlcex=0.8)

它会生成带有填充多边形的常规雷达图.

It produces a regular radar chart with a filled polygon.

但是,我希望内部区域更具色彩,这意味着我想用不同的颜色给每个内部圆上色,而将多边形的外部区域留空,以便类别之间的差异更容易被观众看到**.

However, I would prefer the inner area to be more colourful, meaning I would like to colour each internal circle with different colour, leaving the outern area of the polygon blank, so that the differences between categories are better visible to the audience**.

如果有人知道如何实现这一目标,我将非常感激:)

I would be very grateful if anyone has an idea how to achieve this :)

推荐答案

您可以添加更多数据"来创建与网格对齐的其他多边形. 我为附加数据设置了pcol = NA,这样我们就得到了没有点的多边形. 我做出了一些合理的颜色选择,但请注意,多边形全部重叠,因此颜色会增加.

You can add some more "data" to create additional polygons aligned with the grid. I made pcol=NA for the additional data so that we just get the polygon with no points. I made some plausible color choices, but note that the polygons all overlap, so the colors add.

## Your data with additional polygons aligned to grid
data <- data.frame(rbind(rep(8,14),
          rep(0,14),
          rep(4,14), rep(6,14), rep(8,14),
          c(3,4,4,4,3,4,4,4,4,3,3,3,3,3)))

## Your color - to avoid repetition
COL1 = rgb(0.2,0.5,0.5,0.5)

## Plot
radarchart(data, 
       axistype=1 ,
       pcol=c(NA, NA, NA, COL1),
       pfcol=c("#FF000022", "#FF990022","#FFFF0022", COL1),
       plwd=4,
       cglcol="grey", 
       cglty=1, 
       axislabcol="grey", 
       caxislabels=seq(0,8,2), cglwd=0.8,
       vlcex=0.8)

更新:基于对答案的回答 如果您希望绘制区域的内部是彩色的而外部是白色,则可以添加内圆而不是外圆.

Update: based on response to answer If you want the interior of the plotted region to be colorful and the exterior to be white, you could add the inner circles instead of the outer circles.

data <- data.frame(rbind(rep(8,14),
        rep(0,14),
        c(3,4,4,4,3,4,4,4,4,3,3,3,3,3),
        rep(2,14), rep(0,14)))

## Plot
radarchart(data, 
       axistype=1 ,
       pcol=c("#FF990088", NA,NA),
       pfcol=c("#FF990044","#FFFF0044","#FF000066"),
       plwd=4,
       cglcol="grey", 
       cglty=1, 
       axislabcol="grey", 
       caxislabels=seq(0,8,2), cglwd=0.8,
       vlcex=0.8)

这篇关于是否可以在每个圆具有不同颜色的R中绘制雷达图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆