samedi 22 mai 2021

Change x-axis values and background colour of a plot in R

I have to make a plot of the value of the last column of the following randomly generated dataset (in R):

l<-seq(from=0.2, to=0.3, by=0.02)
output<-as.data.frame(matrix(NA,length(l)*4, 3))
colnames(output)<-c("G", "l", "Value")
output$G<-rep(2:5, each=length(l))
output$l<-rep(l, 4)
output$Value<- rnorm(nrow(output))
plot(output$Value, type="l")  

The plot looks like this now

enter image description here

But I would like, if it is possible, to have on the x-axis the values of the column "l", which is just a vector repeated four times. Regarding the backgroung I was wondering if it is possible to divide the plot into four bins corresponding to the four different values of the column G (e.g., by alternating the colours of the background and adding a legend explaining the corresponding value of G).




Aucun commentaire:

Enregistrer un commentaire