我按照 this tutorial 在 R 中创建了一个雷达图。我采用了教程中的最后一个图表(在引入 ggplot 之前),其中比较了不同情况下的“平均”配置文件。我按照教程建议的方式设置了我的数据,但我希望在“方面”具有相同的最大值和最小值,因此我将其固定为整体最小值和整体最大值。>
数据为:
plot_dat_sameaxis <- structure(list(pol_demo = c(30, 0, 8.97007879362473, 11.0085519474347,
8.53571259274138, 11.2005365744873, 8.71195021047779, 9.7436080644818,
10.399697356034, 7.20225368831287, 7.19846449682537), pol_demo_online = c(30,
0, 9.98019651039727, 11.2121387931753, 10.3544128960645, 12.9789806839878,
10.9067032818662, 10.0244169530494, 10.0412566166562, 9.15927081711705,
7.82259925448071), pol_post_online = c(30, 0, 20.4990544471384,
22.7970962322516, 20.1055172731424, 24.8459684814346, 20.1141933651088,
15.3678777437076, 21.1504832571486, 23.2280265873052, 21.5491092364356
), pol_petition = c(30, 0, 22.4291973933483, 19.4974718426517,
19.2697196682787, 24.3023818310391, 19.5669419418758, 22.3942976741465,
18.8415089525096, 25.983262468582, 28.842684781718), pol_cntct_polit = c(30,
0, 10.7532765882399, 10.815449497248, 12.7134692760538, 7.23126866059413,
11.2047622893094, 11.4708587897729, 9.33114630516778, 9.60620574567012,
10.6909820573769), pol_party = c(30, 0, 8.74403983440336, 7.77898781617009,
9.02365487435948, 7.5573005918663, 9.55902871932231, 10.3628637158336,
9.8557831406188, 7.67193215789611, 7.08669448709292), pol_other = c(30,
0, 11.949458207316, 9.43079720266811, 12.5014350323826, 9.03630081302701,
12.9221923230867, 11.5716131017492, 12.1911878955728, 14.0101290367095,
11.8331630213764), pol_demo_illegal = c(30, 0, 6.67469822553204,
7.45950666840047, 7.49607838697717, 2.84726236356375, 7.01422786895309,
9.0644639572591, 8.18893647629205, 3.13891949840709, 4.97630266469401
)), row.names = c("Max", "Min", "Average", "Only corona freedom",
"Only corona economic", "Corona both", "Corona and other", "Only climate prot.",
"Only racism", "Both racism and climate", "Other"), class = "data.frame")
我将教程中的轴自定义与最后一个绘图代码相结合。所以我首先从网站上获取函数 create_beautiful_radarchart
:
create_beautiful_radarchart <- function(data, color = "#00AFBB",
vlabels = colnames(data), vlcex = 0.7,
caxislabels = NULL, title = NULL, ...){
radarchart(
data, axistype = 1,
# Customize the grid
cglcol = "grey", cglty = 1, cglwd = 0.8,
# Customize the axis
axislabcol = "grey",
# Variable labels
vlcex = vlcex, vlabels = vlabels,
caxislabels = caxislabels, title = title, ...
)
}
那么创建图形的代码是:
opar <- par()
# Define settings for plotting in a 3x4 grid, with appropriate margins:
par(mar = rep(0.8,4))
par(mfrow = c(3,3))
# Produce a radar-chart for each student
for (i in 4:nrow(plot_dat_sameaxis)) {
create_beautiful_radarchart(
plot_dat[c(1:3, i), ],
pfcol = c("#99999980",NA),
pcol= c(NA,2), plty = 1, plwd = 1,
title = row.names(plot_dat_sameaxis)[i],
caxislabels = c(0, 7.5, 15, 22.5, 30)
)
}
我通过设置 caxislabels
向量值将 caxislabels
中的值设置为四个相等的段。首先我想有六个以避免小数,但我得到了一个错误。如果有人可以提供帮助,那也将不胜感激。
然而,更大的问题是,在我运行此代码后,我在图表上获得的值不会反映数据集中的 average
值(中间的阴影区域)。例如,根据图表,pol_party
的平均值应该是大约 15,但在数据集中实际上是 8.74。不明白哪里来的不一样,但是轴标签明显不对。
所以我的问题是,任何人都可以帮助以反映基础数据集的方式整理轴标签,并且可能还有六个而不是五个中断?提前致谢!