首页 > 解决方案 > 在 coord_polar (ggplot2) 中按组分配颜色

问题描述

我需要为弧度图(ggplot2,R)中的每组实例分配不同的颜色。

类似的代码在带有 ggplot2 的条形图中对我很有效,但不适用于雷达图。

colores = c(rgb(79, 129, 189, max=255), rgb(155, 187, 89, max=255), rgb(75, 172, 198, max=255), rgb(44, 77, 117, max=255),rgb(95, 117, 48, max=255))

ggplot(data.m, aes(x = Preguntas, y = Valor, col = Comision, group = Comision), color=Comision) +
  geom_polygon(fill=NA) +
  coord_polar() +
  theme (text = element_text(size=9.5)) +
  theme ( plot.title = element_text(family="Helvetic",
                                    size=rel(2),
                                    vjust=2,
                                    face="plain")) + 
  labs(x = "",y = "") +
  theme(legend.position = "bottom") +
  theme(axis.text.x = element_text(angle=0, hjust=1)) +
  scale_fill_manual(values=colores) +
  scale_y_continuous(limits = c(0.5,1))

我需要您为每个佣金分配不同的颜色,目前可以,但不响应“颜色”列表中的模式。

谢谢!

标签: rggplot2

解决方案


从您的脚本中,您映射color = Comision. 所以,你必须使用scale_color_manual,而不是scale_fill_manual


推荐阅读