Reputation: 35
I have been trying to create a risk radar using plotly and now plotrix, I have encountered limitiations with both (based on my need and also my skillset with R).
With plotly I had pretty much most of the things i wanted except the deal breaker was not being able to label the radial axis (Team A, Team B etc.)
My version of this using plotrix is almost where i need to be and just need some guidance to get me over the line?
I have 4 issues:
Can the title be moved to the left or right?
The radial? labels are bleeding into the chart circle making it hard to read, can they be adjusted somehow?
Is it possible to change the font (size and/or colour) of the labels 0/30/60/90/180?
Is there anyway to add text to the plotted point, in my case i wanted to have the RiskID as the labels
library(plotrix)
# Build sample dataset
aRiskID <- c(1, 15, 23, 28, 35)
bRiskDays <- as.numeric(c(28, 15, 85, 153, 100))
cTheta <- as.integer(c(20, 80, 130, 240, 320))
dConsequence <- c("Major", "Major", "Minor", "Moderate", "Minor")
myRisks <- data.frame(RiskID = aRiskID, RiskDays = bRiskDays, Theta = cTheta, CurrentConsequence = dConsequence)
myLabels <- c("Team A", "Team B", "Team C", "Team D", "Team E", "Team F", "Team G", "Team H")
# Test different point colours
# initializing vector of colors as NA
colors_plot <- rep(NA,length(myRisks))
# set of conditions listed in the plot
colors_plot[myRisks$CurrentConsequence == "Major"] <- "black"
colors_plot[myRisks$CurrentConsequence == "Moderate"] <- "red"
colors_plot[myRisks$CurrentConsequence == "Minor"] <- "green"
# add more conditions as needed
# par(mar=c(2,5,5,5))
# plot the chart
radial.plot(myRisks$RiskDays,
myRisks$Theta,
start = pi/2,
clockwise = FALSE,
# start=pi/2,clockwise=TRUE,
show.grid.labels=1,
rp.type="s",
main="Risk Radar",
radial.lim=c(0,30,60,90,180),
radlab = TRUE,
point.symbols=17,
point.col=colors_plot,
cex = 2,
cex.axis = 0.25,
cex.lab = 0.25,
lwd=par("lwd"),mar=c(2,2,3,2),
# show.centroid=TRUE,
labels=myLabels)
I don't know where else to go with this and so any tips using plotrix or another charting package to achieve the end result would be great.
Upvotes: 0
Views: 778
Reputation: 20811
You should look at the functions radial.plot.labels
and radial.grid
# plot the chart
radial.plot(myRisks$RiskDays,
myRisks$Theta,
start = pi/2,
clockwise = FALSE,
# start=pi/2,clockwise=TRUE,
show.grid.labels=1,
rp.type="s",
# main="Risk Radar",
radial.lim=c(0,30,60,90,180),
radial.labels = '',
radlab = TRUE,
point.symbols=17,
point.col=colors_plot,
cex = 2,
cex.axis = 0.25,
cex.lab = 0.25,
lwd=par("lwd"),mar=c(2,2,3,2),
# show.centroid=TRUE,
labels=NULL, label.pos = pi / 4 * 2:9)
# 1
mtext("Risk Radar", at = par('usr')[1], font = 2)
# 2
at <- c(0,30,60,90,180)
radial.plot.labels(max(at) + 35, pi / 4 * 2:9, labels = myLabels, radial.lim = at)
# 3
radial.plot.labels(at, pi / 2 * 3, labels = at, col = 1:5, cex = 1.5)
# 4
radial.plot.labels(myRisks$RiskDays, myRisks$Theta, start = pi/2,
clockwise = FALSE, labels = myRisks$RiskID)
If you really need perpendicular labels, you can use the radial.grid
function or loop over the labels with separate rotations (srt
). It's a real shame that srt
isn't vectorized in text
, it would make this a lot easier
th <- pi / 4 * 2:9
sapply(seq_along(th), function(ii) {
i <- ifelse((th[ii] > pi / 2) & (th[ii] < pi / 2 * 3), pi, 0)
radial.plot.labels(max(at) + 35, th[ii], labels = myLabels[ii],
radial.lim = at, srt = (th[ii] - i) * 180 / pi)
})
I accidentally made this lovely snowflake @accidental__aRt:
th <- pi / 4 * 2:9
sapply(th, function(x)
radial.plot.labels(max(at) + 35, pi / 4 * 2:9, labels = myLabels,
radial.lim = at, srt = x * 180 / pi))
Upvotes: 1