2

我的问题使用了以下示例: 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(strip.text.x = element_text(size = rel(0.8)),
        axis.text.x = element_text(size = rel(0.8)),
        axis.ticks.y = element_blank(),
        axis.text.y = element_blank()) +
  xlab("") + ylab("") +
  guides(color = guide_legend(ncol=2)) +
  coord_radar()

print(plot)

如何更改绘图/网格最外层线(y 标签下方的线)的颜色?

任何帮助深表感谢!

4

1 回答 1

0

不幸的是,该行由 grid.major 参数控制,但不是显式中断。我发现这样做的唯一方法是取消其余的休息时间,如下所示:

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(strip.text.x = element_text(size = rel(0.8)),
        axis.text.x = element_text(size = rel(0.8)),
        axis.ticks.y = element_blank(),
        axis.text.y = element_blank(),
        panel.grid.major.y = element_line(colour = "blue", size = 0.2), #changed
  xlab("") + ylab("") +
  guides(color = guide_legend(ncol=2)) +
  scale_y_continuous(breaks = NULL) + #changed
  coord_radar()

这使:

在此处输入图像描述

不幸的是,您失去了拥有 y 网格的能力(老实说,如果您没有在极地网格中进行标记,那么无论如何这并不重要)。您可以使用颜色参数更改颜色element_line

于 2016-07-25T23:03:58.693 回答