7

I have 12 variables, M1, M2, ..., M12, for which I compute a certain statistic x.

 df = data.frame(model = factor(paste("M", 1:28, sep = ""), levels=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.

I tried the following:

 ggplot(data=df, aes(x=model, y=x, group=1)) + 
   geom_line() + coord_polar() + 
   scale_y_continuous(limits=range(levels), breaks=levels, labels=levels) +
   theme(axis.text.y = element_blank(), axis.ticks = element_blank(), axis.title.x = element_blank(), axis.title.y = element_blank())

However, I get a disconnected path (between M28 and M1)

enter image description here

Then, I replicated the first row and placed it at the bottom of the dataframe (see below), and then used geom_path() instead of geom_line(), but I didn't get the result I was looking for:

 ## Replicating the first row (model1) and placing it at end of dataframe
 df = rbind(df, df[1,])

 ## using geom_path()

 ggplot(data=df, aes(x=model, y=lg, group=1)) + 
   geom_path() + coord_polar() + 
   scale_y_continuous(limits=range(levels), breaks=levels, labels=levels) +
   theme(axis.text.y = element_blank(), axis.ticks = element_blank(), axis.title.x =  element_blank(), axis.title.y = element_blank())

enter image description here

Could any please help me achieve the result that I am looking for? Any help would be appreciated. Thanks!

1 Answer 1

7

You have to use geom_polygon for closed paths:

library(ggplot2)
ggplot(data=df, aes(x=model, y=x, group=1)) + 
  geom_polygon(fill = NA, colour = "black") + 
  coord_polar() + 
  scale_y_continuous(limits=range(levels), breaks=levels, labels=levels) +
  theme(axis.text.y = element_blank(), axis.ticks = element_blank(), 
        axis.title.x = element_blank(), axis.title.y = element_blank())

enter image description here

Sign up to request clarification or add additional context in comments.

4 Comments

+1 @Mariam, sorry for the misleading comment in your earlier question; I hadn't actually tried it and assumed it would work.
@BrodieG no worries! You were very helpful despite that!
Sven, for some reason, I still get the same result as using geom_path()... I don't know why..
@Mariam I just the first version of df before the rbind command.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.