I just read lot of questions and answers before asking this. But I didn't found the exact answer, resp. it doesn't work.
I have this data frame:
UPDATE #rewrited also in R format:
structure(list(abzufr = structure(c(5L, 3L, 2L, 6L, 4L, 5L), .Label =
c("#NULL!",
"1", "2", "3", "4", "5", "9"), class = "factor"), variable = structure(c(1L,
1L, 1L, 1L, 1L, 2L), class = "factor", .Label = c("überhauptnicht",
"ehernicht", "teilweise", "eherja", "vollundganz")), value =
c("9.90990990990991",
"11.038961038961", "4.98687664041995", "6.55737704918033",
"9.03225806451613",
"22.5225225225225")), .Names = c("abzufr", "variable", "value"), class =
c("data.table", "data.frame"), row.names = c(NA, -6L
), .internal.selfref = <pointer: 0x00000000001f0788>)
I already reshaped this before, so I have the data prepared for doing a bar chart with ggplot2
.
By doing this it comes really strange since the numbers on the y axis are not sorted from 0, but somehow unsorted:
ggplot(Percentage.melt, aes(variable, value, fill = abzufr))+
geom_bar(position = "dodge", stat="identity")+
scale_x_discrete(labels=c("überhaupt nicht", "eher nicht", "teilweise", "eher ja", "voll und ganz"))+
scale_fill_brewer(palette ="YlOrRd", name="Arbeitszufriedenheit", labels=c("resignative Zufriedenheit","konstruktive Unzufriedenheit", "stabilisierte Zufriedenheit","fixierte Unzufriedenheit", "progressive Zufriedenheit"))+
theme_bw()+
theme(axis.title.y = element_blank(), axis.title.x = element_blank(), axis.text.x = element_text(), axis.text.y = element_text())+
ggtitle("Bedenken/Sorgen bezüglich organisationalen Abläufen")`
Before I calculated the percentage of every category by:
library(data.table)
Percentage<-setDT(newdata)[ , .(überhauptnicht = paste0(( nrow(.SD[sil2 ==
"1.0"]) / .N ) * 100),
ehernicht = paste0(( nrow(.SD[sil2 == "2.0"]) / .N ) * 100),
teilweise = paste0(( nrow(.SD[sil2 == "3.0"]) / .N ) * 100),
eherja = paste0(( nrow(.SD[sil2 == "4.0"]) / .N ) * 100),
vollundganz = paste0(( nrow(.SD[sil2 == "5.0"]) / .N ) * 100)) , by =
abzufr]
I tried to round the numbers by
library(dplyr)
Percentage.melt %>% mutate_if(is.numeric, round, digits=2)
and other options discussed here on r and it didn't work. Does anybody know how to round this numbers and make it appear "normal sorted by 0 and higher" on the y axis?
Thankful for every help