I have a set of data which is measured waterflow of wells over a period of years with infrequent dates of measurements.
I made a code which nearly does what i want, but the spacing on the x-axis should correlate to the infrequent dates of measurement. I already googled for a while, may be i am not able to find a given answer due to my lack of experience with R, but i hope someone can point me in the right direction.
Thanks in advance for any given help!
Here is an image of the result i get with my code
The result of my code With even spacing on the x-axis
edit: here a minimalised full working example of the code:
#Einlesen der Daten-----
dat<- read.table("min.txt", header=TRUE, fill=TRUE, sep="\t")
#Checken der Librarys-----
#install.packages("ggplot2") # Installiert das pakent ggplot2 wenn nicht vorhanden
#install.packages("tidyverse")
library(ggplot2) # lädt paket ggplot
library(tidyverse)
#Zuweisen genereller Varialben - Projektdetails
var_gz<-dat$Projektdaten[1]
var_ag<-dat$Projektdaten[2]
var_ort<-dat$Projektdaten[3]
#Zuweisen der Variablen aus den Daten-----
Messdatum<-dat$Messdatum
Nr.1a<-dat$WF.1a
#Plotten der Grafiken
# Ausgaben
plot.width <- 16
plot.height <- 8
#Nr.1a -----
plottitel1="WF 1a"
#plottitel2="xxxxxx"
plotdata1 = Nr.1a
#plotdata2 = xxx
einheit = "l/s"
titel<-paste(var_ort,"/ ",plottitel1)
#----------
ggplot(dat, aes(Messdatum)) + #startet plot, Datum auf xAchse
geom_line(aes(y = plotdata1, colour = plottitel1, group=1)) + #fügt Datenreihe als Linie hinzu
geom_point(aes(y = plotdata1, colour = plottitel1, group=1)) + #fügt Datenreihe als Punkte hinzu
#----Beschriftungselemente----
xlab("Messdatum")+ #X Achses Beschriften
ylab(paste("Messwert [",einheit,"]"))+ #Y Achses Beschriften
ggtitle(titel) #Titel Beschriften
last_plot() + scale_colour_discrete(name="Legende") # ändert Legendentitel
last_plot() + theme(axis.text.x = element_text(size = 10, angle=90, hjust=1)) # dreht Beschriftung xAchse Vertikal
#last_plot() + scale_colour_manual(values=c(2))
last_plot() + theme(legend.position="bottom") # setzte Legende unter Grafik
#Plot Speichern-----
ggsave(filename = paste(var_gz,"_",var_ort,"_",plottitel1,".png"), plot = last_plot(), width = plot.width, height = plot.height, units="cm") #speichert den plot
the inputfile is a .txt named "min.txt" with the following example data:
Projektdaten Messdatum WF 1a
proj nr 2015-10-21 1.000
client 2015-10-22 2.000
location 2015-10-23 3.000
2015-11-30 4.000
2015-12-30 5.000
2016-06-15 6.000
2016-08-25 7.000