Radarchart在循环中的图例 [英] Legend with Radarchart in loop

查看:126
本文介绍了Radarchart在循环中的图例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为循环的一部分,我正在创建几个雷达图.每个图表都是一个国家,在蜘蛛网中显示的信息是几年的数据(不同颜色的线).我正在尝试添加一个图例,以便清楚地说明哪条线(颜色)与哪一年有关.据我所知,radarchart上的帮助文件对此保持沉默. (我在此问题上看到了先前的帖子,但自从我在这里循环工作).我将不胜感激.

As part of a loop I am creating several radarcharts. Each chart is a country, the information displayed in the cobweb are data for several years (lines of different colors). I am trying to add a legend which would make it clear which line (color) relates to which year. As far as I could see, the help file on radarchart is silent on this. (I saw the previous post on this matter, but don't think it's applicable since I am here working in a loop). I would be grateful for any hint.

以下是与循环的一次迭代有关的数据:

Here is the data relating to one iteration of the loop:

require(fmsb)

Radar.tmp<–list(cowc = c("0", "0", "ZIM", "ZIM", "ZIM", "ZIM", 
"ZIM", "ZIM", "ZIM", "ZIM", "ZIM", "ZIM", "ZIM", "ZIM", "ZIM", 
"ZIM"), year = c(0, 0, 1996, 1998, 2000, 2002, 2003, 2004, 2005, 
2006, 2007, 2008, 2009, 2010, 2011, 2012), RoL.Estimate = c(2.5, 
-2.5, -0.82, -0.71, -1.33, -1.59, -1.68, -1.76, -1.77, -1.73, 
-1.78, -1.77, -1.84, -1.81, -1.79, -1.62), GovEff.Estimate = c(2.5, 
-2.5, -0.23, -0.37, -0.78, -0.9, -0.95, -0.95, -1.29, -1.3, -1.27, 
-1.5, -1.52, -1.5, -1.36, -1.21), RegQual.Estimate = c(2.5, -2.5, 
-0.98, -0.79, -1.46, -1.97, -2, -2.03, -2.21, -1.96, -2.16, -2.11, 
-2.1, -2.05, -1.92, -1.83), ControlCorruption.Estimate = c(2.5, 
-2.5, -0.25, -0.65, -0.95, -1.21, -1.25, -1.31, -1.28, -1.33, 
-1.36, -1.31, -1.32, -1.31, -1.38, -1.27), PolStab.Estimate = c(2.5, 
-2.5, -0.53, -0.88, -1.42, -1.6, -1.14, -1.26, -1.24, -0.91, 
-1.11, -1.2, -1.16, -1.12, -0.95, -0.79), VoiceAccount.Estimate = c(2.5, 
-2.5, -0.62, -0.82, -1.11, -1.41, -1.44, -1.55, -1.66, -1.54, 
-1.57, -1.54, -1.54, -1.48, -1.47, -1.45)), .Names = c("cowc", 
"year", "RoL.Estimate", "GovEff.Estimate", "RegQual.Estimate", 
"ControlCorruption.Estimate", "PolStab.Estimate", "VoiceAccount.Estimate"
), row.names = c(1L, 2L, 2689L, 2690L, 2691L, 2692L, 2693L, 2694L, 
2695L, 2696L, 2697L, 2698L, 2699L, 2700L, 2701L, 2702L), class = "data.frame")

这是雷达图的命令:

 radarchart(Radar.tmp[,c("RoL.Estimate","GovEff.Estimate","RegQual.Estimate","ControlCorruption.Estimate","PolStab.Estimate","VoiceAccount.Estimate")], 
             axistype=2, seg=10, pcol=1:8, pty=16, plty=1, maxmin=TRUE, axislabcol="grey", title=c)

这是当前的图形:

请注意,年数(行数)将在循环中的每次迭代之间变化.

Note that the amount of years (number of lines) will change from iteration to iteration in the loop.

我知道雷达图存在一些严重的缺点,但请您暂时将其搁置一旁.

I am aware that there are some serious drawbacks to radarcharts, but would ask you to put them aside for the moment.

非常感谢您的任何提示/建议!

Many thanks for any hint/advice!

推荐答案

找到了我所得到的正在寻找:

Found what I was looking for:

legend(1.5,1, legend=unique(Radar.tmp$year), seg.len=0.5, title="year", pch=1, 
    bty="n" ,lwd=3, y.intersp=0.5, horiz=FALSE, col=unique(Radar.tmp$year))

这篇关于Radarchart在循环中的图例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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