Mayou
Mayou

Reputation: 8828

Plotting level plot in R

I have 12 variables, M1, M2, ..., M12, for which I compute a certain statistic 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:

enter image description here

Each circle (contour) represents the a level of that statistic "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.

Is there any tool in R that allow for such a plot? I tried contour() from library(MASS) but the contours are not drawn as perfect circles.

Any help would be appreciated. Thanks!

Upvotes: 0

Views: 1304

Answers (1)

BrodieG
BrodieG

Reputation: 52647

Here is a ggplot solution:

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)

enter image description here

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.

EDIT: I had to set your factor levels for model in the data frame so they plot in the correct order.

Upvotes: 4

Related Questions