I have spent quite some time adjusting this radarplot, which will be used in about 200 auto-generated reports. The only issue that i cannot seem to solve, is that the axis-labels overlaps with axis-marks. In the attached example, the issue is present in the left side of the plot.
Is there a way that i can decide where these axis-labels are placed? Or maybe place them in an angle, as you can in ggplot?
I would like to keep using fmsb if possible, as i really like the look of these charts.
I have placed a code below, that should give you this result. The image is saved as .png from R in size: w=1000 h=813
segmat <- 7
colors_border=c("#ee7f00", "#00aba4")
colors_in=c("#f6bf8099", "#73d1cd99")
legend <- factor(c("Skole", "Land"))
library(likert)
library(fmsb)
datmat <- structure(list(`Data, Anvendelse` = c(80, 45, 76.9365245227314,
67.0674586834251), `Data, Viden` = c(80, 45, 73.8095238095238,
60.2180860386088), `Data, Ræsonnement` = c(80, 45, 65.6218434343434,
60.9232595763823), `Geometri, Anvendelse` = c(80, 45, 65.4590909090909,
52.8446335193598), `Geometri, Viden` = c(80, 45, 63.1238336316461,
55.0262048394226), `Geometri, Ræsonnement` = c(80, 45, 66.9981060606061,
50.2430105282051), `Tal, Anvendelse` = c(80, 45, 65.9269917792645,
53.701961851033), `Tal, Viden` = c(80, 45, 70.8290320790321,
65.5516016811992), `Tal, Ræsonnement` = c(80, 45, 57.5584072012643,
47.5568952748004)), row.names = c("1", "2", "Skole", "Land"), class = "data.frame")
radarchart(datmat, axistype = 2,
pcol=colors_border , pfcol=colors_in, plwd=3 , plty=1, seg=segmat,
vlcex=1.1, palcex=1.1,
mtext("Procentdel rigtige besvarelser for fagområder. Hver linje angiver en forskel på 5%", col = "darkgrey", font = 4, cex = 1.2),
axislabcol="black")
legend(1.0,-0.8,legend = reverse.levels(legend),
col=colors_border,cex=0.8,
pch = 16, lty =1 , lwd = 3)
title(main = list("Matematik", cex = 1.6, font = 4))
I ended up with the same problem, and you can just copy paste the radarchart()
code and edit it, to add that functionality.
Here's a monkey patch that quickly fixes it on the current version of fmsb
.
patch_fmsb <- function() {
fmsb.env <- environment(fmsb::radarchart)
code <- deparse(fmsb.env$radarchart)
# Axis label nudge
code[60] <- " text(xx[1:n] * r_nudge_caxislabels, yy[1:n] * r_nudge_caxislabels, PAXISLABELS, col = axislabcol)"
code[61] <- " else text(xx[1:n] * r_nudge_caxislabels, yy[1:n] * r_nudge_caxislabels, PAXISLABELS, col = axislabcol, "
# Variable label nudge
code[68] <- " text(xx * 1.2 * r_nudge_vlabels, yy * 1.2 * r_nudge_vlabels, VLABELS)"
code[69] <- " else text(xx * 1.2 * r_nudge_vlabels, yy * 1.2 * r_nudge_vlabels, VLABELS, cex = vlcex)"
# Include parameters in function call
code <- append(code, " r_nudge_caxislabels = 1, r_nudge_vlabels = 1,", after = 5)
rlang::env_binding_unlock(env = fmsb.env)
fmsb.env$radarchart = eval(parse(text = code))
rlang::env_binding_lock(env = fmsb.env)
}
And how to use it, for your example:
segmat <- 7
colors_border=c("#ee7f00", "#00aba4")
colors_in=c("#f6bf8099", "#73d1cd99")
legend <- factor(c("Skole", "Land"))
library(likert)
library(fmsb)
datmat <- structure(list(
`Data, Anvendelse` = c(80, 45, 76.9365245227314, 67.0674586834251),
`Data, Viden` = c(80, 45, 73.8095238095238, 60.2180860386088),
`Data, Ræsonnement` = c(80, 45, 65.6218434343434, 60.9232595763823),
`Geometri, Anvendelse` = c(80, 45, 65.4590909090909, 52.8446335193598),
`Geometri, Viden` = c(80, 45, 63.1238336316461, 55.0262048394226),
`Geometri, Ræsonnement` = c(80, 45, 66.9981060606061, 50.2430105282051),
`Tal, Anvendelse` = c(80, 45, 65.9269917792645, 53.701961851033),
`Tal, Viden` = c(80, 45, 70.8290320790321, 65.5516016811992),
`Tal, Ræsonnement` = c(80, 45, 57.5584072012643, 47.5568952748004)),
row.names = c("1", "2", "Skole", "Land"), class = "data.frame")
patch_fmsb()
radarchart(datmat, axistype = 2,
pcol=colors_border , pfcol=colors_in, plwd=3 , plty=1, seg=segmat,
vlcex=1.1, palcex=1.1,
mtext("Procentdel rigtige besvarelser for fagområder. Hver linje angiver en forskel på 5%", col = "darkgrey", font = 4, cex = 1.2),
axislabcol="black",
r_nudge_caxislabels = 1.05,
r_nudge_vlabels = 1.05)
legend(1.0,-0.8,legend = reverse.levels(legend),
col=colors_border,cex=0.8,
pch = 16, lty =1 , lwd = 3)
title(main = list("Matematik", cex = 1.6, font = 4))