What I currenly have: Plot
What I want to achive: Expectations
The csv file looks like this: CSV file
EDIT:structure form:
| Lp. | P_1_1 | P_1_2 | P_1_3 | P_1_4 | P_1_5 | P_1_6 | P_2_1 | P_2_2 | P_3_1 | P_3_2 | P_4_1 | P_4_2 | P_4_3 | P_4_4 | Wyksztalcenie |
|-----|-------|-------|-------|-------|-------|-------|-------|-------|-------|-------|-------|-------|-------|-------|---------------|
| 1 | 3 | 4 | 4 | 4 | 3 | 3 | 1 | 7 | 7 | 7 | 1 | 3 | 5 | 7 | wyzsze |
| 2 | 3 | 1 | 1 | 5 | 3 | 3 | 1 | 4 | 6 | 4 | 1 | 5 | 3 | 4 | srednie |
| 3 | 3 | 2 | 3 | 4 | 2 | 7 | 1 | 6 | 6 | 6 | 5 | 3 | 4 | 4 | wyzsze |
| 4 | 3 | 3 | 4 | 4 | 3 | 4 | 1 | 5 | 6 | 6 | 3 | 3 | 5 | 5 | srednie |
| 5 | 3 | 1 | 4 | 7 | 3 | 3 | 3 | 6 | 5 | 7 | 5 | 5 | 2 | 2 | srednie |
| 6 | 3 | 4 | 1 | 4 | 3 | 3 | 1 | 6 | 7 | 7 | 7 | 4 | 7 | 5 | srednie |
CSV data after change: CSV after change
Changing the csv data for the chart:
dane <- read.csv2("ankieta.csv", header = TRUE, sep = ";")
temp <- dane %>% count(P_3_1, Wyksztalcenie)
temp$pytanie <- "P_3_1"
colnames(temp) <- c("Lp", "Wykształcenie", "Liczebność", "Pytanie")
temp2 <- dane %>% count(P_3_2, Wyksztalcenie)
temp2$pytanie <- "P_3_2"
colnames(temp2) <- c("Lp", "Wykształcenie", "Liczebność", "Pytanie")
df_merge <- rbind(temp, temp2)
Data structure after change:
| Lp | Wykształcenie | Liczebność | Pytanie |
|----|---------------|------------|---------|
| 1 | podstawowe | 1 | P_3_1 |
| 1 | srednie | 52 | P_3_1 |
| 1 | wyzsze | 65 | P_3_1 |
| 1 | zawodowe | 11 | P_3_1 |
| 2 | podstawowe | 1 | P_3_1 |
| 2 | srednie | 45 | P_3_1 |
Is it possible to prepare the data more simply? It seems to me that I achieved this effect very inelegantly
ggplot2 code:
p1 <-
ggplot(data = df_merge, aes(x = Lp, y = Liczebność, color = Pytanie))+
geom_bar(stat = "identity")+
facet_grid(. ~ Wykształcenie)+
labs(x = "Wykształcenie",
y = "Liczebność",
title = "Rozkład odpowiedzi na pytania grupy 'P_3', w podziale na wykształcenie:")
p1 + scale_x_discrete(name ="Wykształcenie",
limits=c("1","2","3","4","5","6","7"))
Totally don't know:
- How to change the order in which the chart is displayed in order (podstawowe, zawodowe, srednie, wyzsze)
- How to change the size of the chart (grid), display the chart in 2 columns
- How to fill in the whole bar (bar can not be gray)