I would like to make a graph with ggplot as shown below. The idea is to plot "percentage matches" between two categorical variables. It is easy to come close by altering the size of points, but I wondered if it is possible to make these small pie charts...
An example code for plotting this with the size of points as a measure of the score.
temp <- data.frame(Exercise=c(1, 1, 1, 2, 2, 2),
Name=c(1, 2, 3, 1, 2, 3), Score=c(0.2, 0.5, 0.3, 0.9, 1.0, 0.6))
ggplot(temp) + geom_point(aes(Exercise, Name, size=Score))
How can this code be altered to give something close to the figure below?
Using a plot as the shape for a point is tricky. However, you can side step the issue and get very close to your mockup using facet_grid():
First, modify your original data frame to have first 6 rows containing original
score
and last 6 rows contains 1 minus originalscore
. Then added columngroup
containing levels for those two groups.coord_polar()
is used to make piecharts from barplot and thenfacet_grid()
to make six small plots.theme()
is used to remove axis, facet labels, gridlines.