Reputation: 21
I have used the following example for my question: 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)
How do I move the values of the y-axis onto the radar plot so that they align with the major y-axis grid lines and get rid of the black box surrounding the plot?
Upvotes: 2
Views: 1631
Reputation: 29095
You can add the y-axis values as annotated text, and remove the black box by changing the panel.border
parameter in theme(...)
.
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())
Side note: There are too many models in the same chart for this to be easily readable. If you are doing this for practice, that's fine. But if you intend to use it for communicating with others, you may wish to facet the plot so that only a few models are shown in each plot, or choose a different colour scheme that emphasizes only a few models of interest.
Upvotes: 3