首页 > 解决方案 > R中的雷达图 - 雷达图中不可见的变量值和标签太长

问题描述

我正在尝试在 R 中创建雷达图。如何解决这两个问题?

1-变量值不可见

2-变量标签彼此重叠

还有一个问题:

3 - 如何在我的图表中设置渐变色背景(从深灰色到浅灰色)?

我的数据:

> dput(df_radar_final_new)
structure(list(`My input is well received in this clinical area.` = 58, 
    `In this clinical area, it is difficult to speak up when I perceive a problem with patient care.` = 46, 
    `Disagreements in this clinical area are resolved appropriately (i.e., not who is right but what is best for the patient).` = 69, 
    `I have the support I need from my colleagues and other staff groups to care for patients.` = 32, 
    `It is easy for staff here to ask questions when there is something that they do not understand.` = 63), row.names = 1L, class = "data.frame")

我的代码:

install.packages("fmsb")
library(fmsb)

par(mar=c(1, 2, 2, 1)) #decrease default margin
radarchart(df_radar_final_new, maxmin=FALSE)

电流输出: 在此处输入图像描述

图 1 - 运行下面提供的代码后: 在此处输入图像描述

图 2 - 我想要的: 在此处输入图像描述

标签: rvariablesradar-chart

解决方案


您可以通过\n在单词后写入来中断文本以中断文本。

df <- structure(list(`My input is well received in this clinical area.` = 58, 
               `In this clinical area\n, it is difficult to speak up\n when I perceive a problem with patient care.` = 46, 
               `Disagreements in this\n clinical area are resolved appropriately\n (i.e., not who is right but what is best for the patient).` = 69, 
               `I have the support\n I need from my colleagues and other\n staff groups to care for patients.` = 32, 
               `It is easy for staff here\n to ask questions when there\n is something that they do\n not understand.` = 63), row.names = 1L, class = "data.frame")

df

library(fmsb)

par(mar=c(1, 2, 2, 1)) #decrease default margin
radarchart(df, maxmin=FALSE, axistype=3, pty=32, plty=1, axislabcol="red", na.itp=FALSE,
           title="(no points, axis=3, na.itp=FALSE)")

我玩了一下,你必须改变axislabcol才能看到你的价值观。这是文档:https ://rdrr.io/cran/fmsb/man/radarchart.html =>我找不到改变背景颜色的方法。


推荐阅读