I have a simple question to which I can't find a solution
here is my dataset
df <- structure(list(var = c(1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3,
4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4,
5), key = structure(c(4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L,
6L, 6L, 6L, 6L, 6L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 7L,
7L, 7L, 7L, 7L, 3L, 3L, 3L, 3L, 3L), levels = c("D", "E", "G",
"A", "B", "C", "F"), class = "factor"), value = c(71.5862363478496,
37.8203087607194, 21.8481932821862, 14.3252994774026, 43.9673840073536,
0.970554134149992, 10.2169427632967, 0.482211443593141, 27.1986646339779,
0, 7.53079829570694, 2.99274245246759, 0, 1.18270390573516, 36.5445689931181,
7.34657218944321, 31.9825027122446, 65.498610956116, 19.4131071594402,
3.29473510264364, 0.524263480063698, 1.59031872629643, 0.901030900406403,
0.342812345032694, 0.225194597739533, 0.122185299688452, 3.60412401295608,
5.07823210446615, 18.5641921443332, 0, 11.9193902530981, 11.7930605720191,
6.19172131323217, 18.9732203340783, 15.9681172991452), median = c(0.249672472831354,
0.0119657156700395, -0.581064311371051, 0.167134320110767, 0.0950594757449505,
0.249672472831354, 0.0119657156700395, -0.581064311371051, 0.167134320110767,
0.0950594757449505, 0.249672472831354, 0.0119657156700395, -0.581064311371051,
0.167134320110767, 0.0950594757449505, 0.249672472831354, 0.0119657156700395,
-0.581064311371051, 0.167134320110767, 0.0950594757449505, 0.249672472831354,
0.0119657156700395, -0.581064311371051, 0.167134320110767, 0.0950594757449505,
0.249672472831354, 0.0119657156700395, -0.581064311371051, 0.167134320110767,
0.0950594757449505, 0.249672472831354, 0.0119657156700395, -0.581064311371051,
0.167134320110767, 0.0950594757449505)), row.names = c(NA, -35L
), class = "data.frame")
I want to create a single figure with "var" on the x-axis and "median" on the y-axis, and instead of the geom_point I want to use "value" piecharts. I give you the example codes
# Note that I want the final figure to be reordered
df %>% ggplot(aes(x=reorder(var, median), y=median)) +
geom_point()
and
df %>% filter(var == 1) %>%
ggplot(aes(x="", y=value, fill=key)) +
geom_bar(stat="identity", color="white") +
coord_polar("y", start=0) +
theme_void() + theme(legend.position="none")
So I would like to have 5 piecharts in my figure at the "median" level (so they will not be at the same level). I imagined creating an empty ggplot and putting the piecharts at x, y coordinates for example (something like that but there may be simpler ways). I would also like this figure to be a unique legend of "key" (or not).
Thank you very much