【问题标题】:how to place Y-axis values within radar chart如何在雷达图中放置 Y 轴值
【发布时间】:2018-05-03 08:32:42
【问题描述】:

我的问题使用了以下示例:http://www.cmap.polytechnique.fr/~lepennec/R/Radar/RadarAndParallelPlots.html

mtcarsscaled <- as.data.frame(lapply(mtcars, ggplot2:::rescale01))
mtcarsscaled$model <- rownames(mtcars)
mtcarsmelted <- reshape2::melt(mtcarsscaled)

coord_radar <- function (theta = "x", start = 0, direction = 1) 
{
  theta <- match.arg(theta, c("x", "y"))
  r <- if (theta == "x") 
    "y"
  else "x"
  ggproto("CordRadar", CoordPolar, theta = theta, r = r, start = start, 
          direction = sign(direction),
          is_linear = function(coord) TRUE)
}

plot <- ggplot(mtcarsmelted, aes(x = variable, y = value)) +
  geom_polygon(aes(group = model, color = model), fill = NA, size = 2, show.legend = FALSE) +
  geom_line(aes(group = model, color = model), size = 2) +
  theme_bw()+
  theme(axis.text.x = element_text(colour="black",size=10), axis.text.y=element_text(size=14))+
  xlab("") + ylab("") +
  guides(color = guide_legend(ncol=2)) +
  coord_radar()

print(plot)

如何将 y 轴的值移动到雷达图上,以便它们与主要的 y 轴网格线对齐并消除图周围的黑框?

【问题讨论】:

    标签: r ggplot2 radar-chart


    【解决方案1】:

    您可以将 y 轴值添加为带注释的文本,并通过更改 theme(...) 中的 panel.border 参数来移除黑框。

    ggplot(mtcarsmelted, aes(x = variable, y = value)) +
      geom_polygon(aes(group = model, color = model), 
                   fill = NA, size = 2, show.legend = FALSE) +
      geom_line(aes(group = model, color = model), size = 2) +
      xlab("") + ylab("") +
      guides(color = guide_legend(ncol = 2)) +
      coord_radar() +
      theme_bw()+
    
      # annotate
      annotate("text", x = 0, 
               y = seq(0, 1, 0.25), 
               label = seq(0, 1, 0.25)) +
    
      # remove original y-axis text / ticks & black border
      theme(axis.text.x = element_text(colour="black", size=10), 
            axis.text.y = element_blank(),
            axis.ticks.y = element_blank(),
            panel.border = element_blank()) 
    

    旁注:同一张图表中的模型太多,难以阅读。如果你这样做是为了练习,那很好。但如果您打算使用它与他人交流,您可能希望对情节进行分面,以便在每个情节中仅显示几个模型,或者选择仅强调少数感兴趣的模型的不同配色方案。

    【讨论】:

    • 以前面的示例为基础,如果我想在图形的外边缘上方添加一个额外的标签环,我该怎么做?例如,如果有一个额外的类别说明汽车型号是柴油、汽油、电动还是混合动力,我想在图表上显示这一点。 (这只是一个假设性问题,我想将其应用于显示季节的径向图表)。
    • @MariettePretorius 你能用你的意思的草图更新你的问题吗?我不确定我是否明白你的意思。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-15
    • 1970-01-01
    相关资源
    最近更新 更多