Closing the lines in a ggplot2 radar / spider chart

后端 未结 6 1982
时光取名叫无心
时光取名叫无心 2020-12-16 07:11

I need a flexible way to make radar / spider charts in ggplot2. From solutions I\'ve found on github and the ggplot2 group, I\'ve come this far:

library(ggpl         


        
6条回答
  •  庸人自扰
    2020-12-16 08:02

    It turns out than geom_polygom still produces a polygon in the polar coordinates so that

    # rescale all variables to lie between 0 and 1
    scaled <- as.data.frame(lapply(mtcars, ggplot2:::rescale01))
    scaled$model <- rownames(mtcars)    # add model names as a variable
    # melt the dataframe
    mtcarsm <- reshape2::melt(scaled)
    # plot it as using the polygon geometry in the polar coordinates
    ggplot(mtcarsm, aes(x = variable, y = value)) +
    geom_polygon(aes(group = model), color = "black", fill = NA, size = 1) +
    coord_polar() + facet_wrap( ~ model) +
    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("")
    

    works perfectly...

提交回复
热议问题