我最近一直在研究雷达图,并从Erwan Le Pennec找到了大量代码。我做了一些编辑,但是有些部分我无法弄清楚如何删除最外层的圆圈,因为它没有定义一个值。目前代码正在绘制主要的网格线。我试图欺骗它删除两个轴并仅绘制较小的增量,但是任何一个都有效。
干杯!
这是我的代码:
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)
}
RadarTheme<-theme(panel.background=element_blank(),
plot.title= element_text(size = 25,face=c("bold","italic")),
plot.margin = unit(c(2, 2, 2, 2), "cm"),
text=element_text(family="Open Sans"), aspect.ratio = 1,
legend.position="bottom",legend.title=element_blank(),legend.direction="vertical",
strip.text.x = element_text(size = rel(0.8)),
axis.text.x = element_text(size = 15,face ="bold"),
axis.ticks.y = element_blank(),
axis.text.y = element_blank(),
axis.line.x=element_line(size=0.5),
panel.grid.major=element_line(size=0.3,linetype = 2,colour="grey"))
mtcarsscaled <- as.data.frame(lapply(mtcars, ggplot2:::rescale01))
mtcarsscaled$model <- rownames(mtcars)
mtcarsscaled1<-subset(mtcarsscaled,model=="Lotus Europa")
mtcarsscaled2<-subset(mtcarsscaled,model=="Volvo 142E")
mtcarsscaled<-rbind(mtcarsscaled1,mtcarsscaled2)
mtcarsmelted <- reshape2::melt(mtcarsscaled)
mtcarsmelted$value<-mtcarsmelted$value*100
c<-ggplot(mtcarsmelted, aes(x = variable, y = value)) +
geom_polygon(aes(group = model, color = model,fill = model),alpha=0.4, size = 1, show.legend = TRUE) +
RadarTheme+
xlab("") + ylab("") +scale_y_continuous(limits = c(-5, 100), breaks = seq(0, 100, 25))+
coord_radar()+
guides(fill = guide_legend(keywidth = rel(1.3), keyheight = rel(1.3)))
print(c)