Hi everybody
i am new in R studi and have a problem with the y-scale:
I have made a graphic (geom_bar, geom_line). However, I cannot set the scaling of the y-axis dynamically (as in Excel). Depending on the filter setting, the output has other values, instead of millions only 100'000. Unfortunately, this y-scaling is then not displayed. Can anyone help me further on how I can set the y-axis dynamically - depending on the filtered data base.
Here my Code:
# dataset <- data.frame(Datum, Region (manuell eingefügte Spalte), Betrag, Betrag in, Betrag out, Diff Betrag IN OUT)
# dataset <- unique(dataset)
# Fügen oder geben Sie hier Ihren Skriptcode ein:
library(ggplot2)
names(dataset) <- c("Datum", "Region", "Betrag", "Betragin", "Betragout", "Diff")
dataset$group <- c(1)
dataset[is.na(dataset)] = 0
ggplot(dataset)+
geom_bar(mapping = aes(x=substr(Datum,start=1,stop=8), y=Betragin/1000000, fill="Betragin/1000000"), stat="identity",, width=0.8)+
geom_bar(mapping= aes(x=substr(Datum,start=1,stop=8), y=Betragout/1000000, fill="Betragout/1000000"), stat="identity", width=0.8)+
geom_point(mapping= aes(x=substr(Datum,start=1,stop=8), y=Diff/1000000, group=group, fill="Diff/1000000"), color="NA", size=1) +
geom_line(mapping= aes(x=substr(Datum,start=1,stop=8), y=Diff/1000000, group=group, fill="Diff/1000000"), color="#666666", size=1)+
theme_gray(base_size=12)+
labs(x="",y="CHF in Mio.")+
scale_y_continuous(limits=c(min(dataset$Betragout/1000000),max(dataset$Betragin/1000000)), breaks = seq(-100000,100000, by=0.5), minor_breaks=seq(-100000,100000, by=0.1))+
theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1))+
scale_color_manual(values=c("#37A794","#dd667f", "#666666"),
name="", labels=c("Betrag In", "Betrag Out", "Differenz In Out"))+
scale_fill_manual(values=c("#37A794","#dd667f", "#666666"),
name="", labels=c("Betrag In", "Betrag Out", "Differenz In Out"))+
theme(legend.position = "bottom")+
facet_grid(~Region)
Thank you for your help
best regard
kaha