简体   繁体   English

在R中绘制水平图

[英]Plotting level plot in R

I have 12 variables, M1, M2, ..., M12 , for which I compute a certain statistic x . 我有12个变量M1,M2,...,M12 ,为此我计算了一定的统计量x

 df = data.frame(model = paste("M", 1:28, sep = ""), x = runif(28, 1, 1.05))
 levels = seq(0.8, 1.2, 0.05)

I would like to plot this data as follows: 我想按以下方式绘制此数据:

在此处输入图片说明

Each circle (contour) represents the a level of that statistic "x" . 每个圆圈(轮廓)代表该统计量“ x”的水平 The three blue lines simply represent three different scenarios. 三个蓝线仅表示三种不同的情况。 The dataframe included in this example represents one scenario. 此示例中包括的数据帧代表一种情况。 The blue line would simply join the values of all the models M1 to M28 for that specific scenario. 蓝线将简单地连接该特定方案的所有模型M1M28的值。

Is there any tool in R that allow for such a plot? R中是否有任何工具可以绘制这样的图? I tried contour() from library(MASS) but the contours are not drawn as perfect circles. 我尝试了来自library(MASS)的轮廓contour() ,但是轮廓线并未绘制为完美的圆。

Any help would be appreciated. 任何帮助,将不胜感激。 Thanks! 谢谢!

Here is a ggplot solution: 这是一个ggplot解决方案:

library(ggplot2)
ggplot(data=df, aes(x=model, y=x, group=1)) + 
  geom_line() + coord_polar() + 
  scale_y_continuous(limits=range(levels), breaks=levels, labels=levels)

在此处输入图片说明

Note this is a little confusing because of the names in your data frame. 注意,由于数据框中的名称,这有点令人困惑。 x is really the y variable here, and model the real x , so the graph scale label seems odd. x在这里实际上是y变量,并对真实x建模,因此图形比例标签看起来很奇怪。

EDIT: I had to set your factor levels for model in the data frame so they plot in the correct order. 编辑:我必须在数据框中设置model的因子水平,以便它们以正确的顺序绘制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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