Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pedal chart script #2

Open
wageningen opened this issue Nov 18, 2016 · 0 comments
Open

Pedal chart script #2

wageningen opened this issue Nov 18, 2016 · 0 comments

Comments

@wageningen
Copy link
Collaborator

wageningen commented Nov 18, 2016

A remark, perhaps useful. I got a request from a colleague of ISRIC to create in R a pedal chart, also called rose chart, like this (the data are fictional):
example_rose_plot.
As I couldn't find a function or package, I wrote something myself. It will probably need adjustments (for example, I made it static: it can only show six leaves), but for inspiration, this is the code:

## script for plotting six roses in polar plot - "Pedal chart" 
# Luc Steinbuch, 22/10/2016

#You need to install this package one time: 
install.packages('plotrix')

# and load it..
require(plotrix)

# mathematical background: 
# browseURL("http://www.shelovesmath.com/trigonometry/polar-graphs/#DrawingGraphs")
# and then the "Rose" section


## Note: script works only for 6 roses!

## creating data frame
# first column: value of rose (between 0 and 1)
# second colum: corresponding color. See browseURL("http://www.stat.columbia.edu/~tzheng/files/Rcolor.pdf")
# third column: corresponding label 
df_roses <- data.frame(c(0.8, 0.5, 0.95, 0.8, 0.75, 0.6),
         c("lightgreen", "orange", "green", "lightgreen", "lightgreen", "grey90"),
         c("Soil Organic Carbon", "Yield", "Earthworms", "Water holding capacity", "Aggregate stability", "pH" ) ,
         stringsAsFactors = FALSE
         )
names(df_roses) <- c("Value", "Color", "Label")

View(df_roses)


## For our convenience: data frame with angles corresponding to the roses, 
# because a polar plot is angle-based
df_angles <- data.frame(2*pi/6*(0:5), 
                        2*pi/6*(1:6),
                        2*pi/6*seq(from = 0.5, to=5.5, by=1)
) 
names(df_angles) <- c("Start", "End", "Center")

#View(df_angles)


## first create empty plot, with labels
# labels cannot be added later :-(
radial.plot( lengths    = NA,
             radial.pos = NA,
             main       = "No-till versus conventional till",
             radial.lim = c(0,1),
             show.grid.labels = TRUE,
             show.radial.grid = TRUE,
             label.pos        = df_angles$Center,
             labels           = df_roses$Label
            )





## add roses one by one with for-loop
for (i in 1:6)
{
  vn_angle <- seq(from = df_angles$Start[i], to = df_angles$End[i], length=100)
  vn_rose  <-  abs( sin(vn_angle*6/2)*df_roses$Value[i] ) 
  
  radial.plot( lengths    = vn_rose,
               radial.pos = vn_angle,
               rp.type    = "p",
               line.col   = "black",
               poly.col   = df_roses$Color[i],
               add        = TRUE
          )
}


# draw the "no change" circle
n_no_change_value <- 0.6
vn_angle  <- seq(0, to = 2*pi, length=100)
vn_circle <- rep(x=n_no_change_value, times=100)
  
radial.plot( lengths      = vn_circle,
               radial.pos = vn_angle,
               radial.lim = c(0,1),
               rp.type    = "p",
               line.col   = "blue",
               add        = TRUE
          )

# add "no change" text
text(x      = 0, 
     y      = n_no_change_value + 0.05, # you can adjust this
     labels = "No change", 
     col    = "blue")

created by @LucSteinbuch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants