R语言 调整雷达图上的轴标(fmsb)

idfiyjo8  于 2023-11-14  发布在  其他
关注(0)|答案(1)|浏览(113)

我已经花了相当长的时间来调整这个雷达图,它将被用于大约200个自动生成的报告。唯一的问题,我似乎不能解决,是轴标签与轴标记重叠。在所附的例子中,这个问题存在于图的左侧。
有没有一种方法可以让我决定这些轴标签的位置?或者像ggplot一样把它们放在一个Angular 上?
如果可能的话,我想继续使用fmsb,因为我真的很喜欢这些图表的外观。
我在下面放了一个代码,应该给予你this result。图像保存为.png从R大小: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))

字符串

ha5z0ras

ha5z0ras1#

我最终遇到了同样的问题,你可以复制粘贴radarchart()代码并编辑它,以添加该功能。
这里有一个猴子补丁,可以快速修复当前版本的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)
}

字符串
如何使用它,例如:

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))

相关问题