I would like to improve my chart by doing two things. First, I want to add a point that contains the mean value for each variable. Second, I want to make the point size a function of how many times the value is actually present in each variable. If you have any other suggestions on how to make my graph clearer, pls to hesitate to propose them to me. Thank you a lot !
MD4_long <- MD4 %>%
pivot_longer(everything()) %>%
mutate(value = as.numeric(value) - 3,
value = ifelse(value == 3, NA, value)) %>%
group_by(name)
ggplot(MD4_long, aes(x = value, y = reorder(name, value)))
geom_point(aes (colour = value, size = 3))
scale_y_discrete(labels = ~gsub("^.*_", "", .x))
theme_light()
scale_colour_viridis_c(aesthetics = "colour")
labs(x = NULL, y = NULL)
structure(list(veränderung_imap_austausch.verstärkt.akteuren = structure(c(3L,
4L, NA, NA, 3L, 4L, 4L, 3L, NA, NA, NA, NA, NA, NA, NA, 3L, NA,
NA, NA, NA, NA, 4L, NA, NA, NA, NA, 3L, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, 5L, NA, 4L, NA, NA, NA, NA, NA, 5L, 4L, NA, NA, NA, 4L, 3L,
NA, NA, NA, NA, NA, NA, NA, NA, 5L, 3L, 4L, NA, NA, NA, 4L, 4L,
NA, 1L, 4L, NA, 3L, 4L, 3L, NA, NA, NA, 5L, 5L, 3L, NA, NA, NA,
5L, NA, 1L, 4L, NA, 4L, NA, 4L, 4L, 4L, 3L, 3L, 3L, NA, 3L, 6L,
2L), .Label = c("Stimme nicht zu", "Stimme eher nicht zu", "Stimme teilweise zu",
"Stimme zu", "Stimme voll zu", "k. A."), class = c("ordered",
"factor")), veränderung_imap_austausch.verstärkt.ideen = structure(c(5L,
4L, NA, NA, 3L, 4L, 4L, 2L, NA, NA, NA, NA, NA, NA, NA, 4L, NA,
NA, NA, NA, NA, 4L, NA, NA, NA, NA, 4L, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, 5L, NA, 4L, NA, NA, NA, NA, NA, 4L, 4L, NA, NA, NA, 4L, 3L,
NA, NA, NA, NA, NA, NA, NA, NA, 5L, 4L, 5L, NA, NA, NA, 4L, 4L,
NA, 3L, 4L, NA, 2L, 4L, 4L, NA, NA, NA, 5L, 5L, 3L, NA, NA, NA,
5L, NA, 4L, 4L, NA, 4L, NA, 3L, 5L, 4L, 3L, 4L, 4L, NA, 4L, 6L,
3L), .Label = c("Stimme nicht zu", "Stimme eher nicht zu", "Stimme teilweise zu",
"Stimme zu", "Stimme voll zu", "k. A."), class = c("ordered",
"factor")), veränderung_imap_fortschritt.umsetzung = structure(c(4L,
4L, NA, NA, 3L, 4L, 6L, 3L, NA, NA, NA, NA, NA, NA, NA, 4L, NA,
NA, NA, NA, NA, 4L, NA, NA, NA, NA, 4L, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, 4L, NA, 4L, NA, NA, NA, NA, NA, 5L, 3L, NA, NA, NA, 4L, 3L,
NA, NA, NA, NA, NA, NA, NA, NA, 4L, 3L, 4L, NA, NA, NA, 4L, 4L,
NA, 3L, 4L, NA, 3L, 3L, 4L, NA, NA, NA, 5L, 5L, 3L, NA, NA, NA,
5L, NA, 3L, 3L, NA, 4L, NA, 3L, 5L, 3L, 4L, 2L, 3L, NA, 3L, 6L,
3L), .Label = c("Stimme nicht zu", "Stimme eher nicht zu", "Stimme teilweise zu",
"Stimme zu", "Stimme voll zu", "k. A."), class = c("ordered",
"factor")), veränderung_imap_neue.strukturen = structure(c(4L,
4L, NA, NA, 3L, 4L, 4L, 3L, NA, NA, NA, NA, NA, NA, NA, 3L, NA,
NA, NA, NA, NA, 3L, NA, NA, NA, NA, 3L, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, 3L, NA, 4L, NA, NA, NA, NA, NA, 5L, 3L, NA, NA, NA, 4L, 3L,
NA, NA, NA, NA, NA, NA, NA, NA, 4L, 4L, 3L, NA, NA, NA, 4L, 4L,
NA, 3L, 4L, NA, 3L, 4L, 4L, NA, NA, NA, 5L, 4L, 3L, NA, NA, NA,
5L, NA, 5L, 3L, NA, 5L, NA, 3L, 5L, 3L, 2L, 2L, 2L, NA, 2L, 6L,
1L), .Label = c("Stimme nicht zu", "Stimme eher nicht zu", "Stimme teilweise zu",
"Stimme zu", "Stimme voll zu", "k. A."), class = c("ordered",
"factor")), veränderung_imap_zuständigkeiten.klarer = structure(c(3L,
3L, NA, NA, 3L, 4L, 6L, 3L, NA, NA, NA, NA, NA, NA, NA, 2L, NA,
NA, NA, NA, NA, 3L, NA, NA, NA, NA, 3L, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, 3L, NA, 4L, NA, NA, NA, NA, NA, 3L, 3L, NA, NA, NA, 3L, 3L,
NA, NA, NA, NA, NA, NA, NA, NA, 3L, 3L, 4L, NA, NA, NA, 3L, 3L,
NA, 4L, 3L, NA, 3L, 3L, 4L, NA, NA, NA, 5L, 4L, 3L, NA, NA, NA,
5L, NA, 2L, 4L, NA, 3L, NA, 3L, 3L, 3L, 3L, 2L, 2L, NA, 4L, 6L,
2L), .Label = c("Stimme nicht zu", "Stimme eher nicht zu", "Stimme teilweise zu",
"Stimme zu", "Stimme voll zu", "k. A."), class = c("ordered",
"factor")), veränderung_imap_rollen.klarer = structure(c(3L,
3L, NA, NA, 3L, 4L, 6L, 2L, NA, NA, NA, NA, NA, NA, NA, 3L, NA,
NA, NA, NA, NA, 3L, NA, NA, NA, NA, 2L, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, 4L, NA, 4L, NA, NA, NA, NA, NA, 3L, 1L, NA, NA, NA, 3L, 3L,
NA, NA, NA, NA, NA, NA, NA, NA, 3L, 3L, 1L, NA, NA, NA, 4L, 3L,
NA, 4L, 1L, NA, 3L, 4L, 4L, NA, NA, NA, 5L, 4L, 3L, NA, NA, NA,
5L, NA, 2L, 3L, NA, 3L, NA, 3L, 4L, 3L, 2L, 3L, 3L, NA, 4L, 6L,
4L), .Label = c("Stimme nicht zu", "Stimme eher nicht zu", "Stimme teilweise zu",
"Stimme zu", "Stimme voll zu", "k. A."), class = c("ordered",
"factor")), veränderung_imap_digitale.lösungen = structure(c(4L,
4L, NA, NA, 5L, 4L, 4L, 4L, NA, NA, NA, NA, NA, NA, NA, 3L, NA,
NA, NA, NA, NA, 4L, NA, NA, NA, NA, 6L, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, 5L, NA, 4L, NA, NA, NA, NA, NA, 5L, 4L, NA, NA, NA, 4L, 3L,
NA, NA, NA, NA, NA, NA, NA, NA, 1L, 3L, 4L, NA, NA, NA, 5L, 5L,
NA, 6L, 5L, NA, 4L, 4L, 4L, NA, NA, NA, 4L, 5L, 6L, NA, NA, NA,
4L, NA, 1L, 5L, NA, 4L, NA, 4L, 5L, 5L, 4L, 4L, 4L, NA, 4L, 6L,
4L), .Label = c("Stimme nicht zu", "Stimme eher nicht zu", "Stimme teilweise zu",
"Stimme zu", "Stimme voll zu", "k. A."), class = c("ordered",
"factor")), veränderung_imap_klarheit.prozesse = structure(c(5L,
3L, NA, NA, 4L, NA, NA, 4L, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, 4L, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, 4L, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 4L, NA, NA, NA, NA, NA,
NA, 3L, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, 5L, NA, NA, 5L, 5L, 3L, 4L, 4L, NA, 3L, 6L,
4L), .Label = c("Stimme nicht zu", "Stimme eher nicht zu", "Stimme teilweise zu",
"Stimme zu", "Stimme voll zu", "k. A."), class = c("ordered",
"factor")), veränderung_imap_weiterent.planung = structure(c(5L,
3L, NA, NA, 3L, NA, NA, 3L, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, 4L, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, 5L, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 4L, NA, NA, NA, NA, NA,
NA, 3L, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, 4L, NA, NA, 4L, 5L, 3L, 4L, 4L, NA, 3L, 6L,
4L), .Label = c("Stimme nicht zu", "Stimme eher nicht zu", "Stimme teilweise zu",
"Stimme zu", "Stimme voll zu", "k. A."), class = c("ordered",
"factor")), veränderung_imap_arbeit.relfelktieren = structure(c(4L,
3L, NA, NA, 4L, NA, NA, 4L, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, 4L, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, 5L, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 5L, NA, NA, NA, NA, NA,
NA, 3L, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, 4L, NA, NA, 3L, 5L, 3L, 4L, 4L, NA, 4L, 6L,
4L), .Label = c("Stimme nicht zu", "Stimme eher nicht zu", "Stimme teilweise zu",
"Stimme zu", "Stimme voll zu", "k. A."), class = c("ordered",
"factor")), veränderung_imap_veranstaltung.ergebnisorientiert = structure(c(6L,
4L, NA, NA, 5L, NA, NA, 3L, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, 5L, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, 5L, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 5L, NA, NA, NA, NA, NA,
NA, 4L, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, 5L, NA, NA, 5L, 5L, 3L, 3L, 3L, NA, 6L, 6L,
3L), .Label = c("Stimme nicht zu", "Stimme eher nicht zu", "Stimme teilweise zu",
"Stimme zu", "Stimme voll zu", "k. A."), class = c("ordered",
"factor")), veränderung_imap_motivation = structure(c(5L, 4L,
NA, NA, 5L, NA, NA, 4L, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, 4L, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, 4L, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, 5L, NA, NA, NA, NA, NA, NA,
4L, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, 5L, NA, NA, 5L, 5L, 4L, 4L, 4L, NA, 3L, 6L, 4L
), .Label = c("Stimme nicht zu", "Stimme eher nicht zu", "Stimme teilweise zu",
"Stimme zu", "Stimme voll zu", "k. A."), class = c("ordered",
"factor")), veränderung_imap_salienz = structure(c(3L, 4L, NA,
NA, 5L, NA, NA, 2L, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, 3L, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, 2L, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, 4L, NA, NA, NA, NA, NA, NA, 3L,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, 4L, NA, NA, 3L, 4L, 4L, 4L, 3L, NA, 4L, 6L, 3L), .Label = c("Stimme nicht zu",
"Stimme eher nicht zu", "Stimme teilweise zu", "Stimme zu", "Stimme voll zu",
"k. A."), class = c("ordered", "factor")), veränderung_imap_interkult.öffnung = structure(c(3L,
4L, NA, NA, 3L, NA, NA, 2L, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, 4L, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, 2L, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 3L, NA, NA, NA, NA, NA,
NA, 3L, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, 4L, NA, NA, 3L, 4L, 3L, 3L, 6L, NA, 3L, 6L,
2L), .Label = c("Stimme nicht zu", "Stimme eher nicht zu", "Stimme teilweise zu",
"Stimme zu", "Stimme voll zu", "k. A."), class = c("ordered",
"factor")), veränderung_imap_austausch.kommunen.verstärkt = structure(c(4L,
4L, NA, NA, 4L, NA, NA, 4L, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, 4L, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, 2L, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 5L, NA, NA, NA, NA, NA,
NA, 6L, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, 3L, NA, NA, 4L, 2L, 3L, 2L, 6L, NA, 2L, 6L,
4L), .Label = c("Stimme nicht zu", "Stimme eher nicht zu", "Stimme teilweise zu",
"Stimme zu", "Stimme voll zu", "k. A."), class = c("ordered",
"factor")), veränderung_imap_einarbeitung = structure(c(3L, 3L,
NA, NA, 5L, NA, NA, 2L, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, 4L, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, 4L, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, 4L, NA, NA, NA, NA, NA, NA,
6L, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, 4L, NA, NA, 4L, 1L, 1L, 2L, 1L, NA, 6L, 6L, 4L
), .Label = c("Stimme nicht zu", "Stimme eher nicht zu", "Stimme teilweise zu",
"Stimme zu", "Stimme voll zu", "k. A."), class = c("ordered",
"factor")), veränderung_imap_einsatz.vielfalt.verstärkt = structure(c(3L,
4L, NA, NA, 3L, NA, NA, 3L, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, 3L, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, 3L, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 3L, NA, NA, NA, NA, NA,
NA, 6L, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, 3L, NA, NA, 4L, 3L, 3L, 2L, 3L, NA, 6L, 6L,
2L), .Label = c("Stimme nicht zu", "Stimme eher nicht zu", "Stimme teilweise zu",
"Stimme zu", "Stimme voll zu", "k. A."), class = c("ordered",
"factor"))), row.names = c(NA, -114L), class = "data.frame")
CodePudding user response:
You just need to count the number of occurrences of each category/value pair and use this in the aes(size=)
function. You also need to calculate the mean of each value and the pass a second geom_point()
to the graph.
library(ggplot2)
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library(tidyverse)
MD4_long <- MD4 %>%
pivot_longer(everything()) %>%
mutate(value = as.numeric(value) - 3,
value = ifelse(value == 3, NA, value)) %>%
group_by(name, value) %>%
summarise(count = n()) %>%
ungroup() %>%
group_by(name) %>%
mutate(mean = mean(value, na.rm = T))
#> `summarise()` has grouped output by 'name'. You can override using the `.groups` argument.
ggplot(MD4_long, aes(x = value, y = reorder(name, value)))
geom_point(aes (size = count))
geom_point(aes (x = mean), colour = "red")
scale_y_discrete(labels = ~gsub("^.*_", "", .x))
theme_light()
scale_colour_viridis_c(aesthetics = "colour")
labs(x = NULL, y = NULL)
#> Warning: Removed 17 rows containing missing values (geom_point).
Created on 2022-04-25 by the reprex package (v2.0.0)