I used scale() function on my data to avoid high correlation when doing a mixed model. Now I want the original values to appear in my plot. So I reversed the scaling with
x * attr(x, 'scaled:scale') + attr(x, 'scaled:center')
and put the values in a new column of the dataframe that I use to plot. So as an example my data now looks something like this, where x is the real value and x.s the scaled value:
x <- sample(x=1:100, size = 50)
y <- sample(x=1:100, size = 50)
df <- as.data.frame(cbind(x,y))
df$x.s <- scale(df$x)
I want to plot this now with ggplot but show the values of x on x-axis and not the scaled values of x.s, so i did the following:
ggplot(df, aes(x=x.s, y=y))+
geom_point()+
scale_x_continuous(labels=df$x, breaks = df$x.s)+
labs(x="Canopy openness [%]",y="Rarefied richness") + theme_bw()
This works so far and the output looks someting like this:
My Problem now is, that i want the ticks on the x-Axis spread evenly which I would usually do with breaks=seq(0,100,10), but breaks is already defined to avoid error Error in f(..., self = self) : Breaks and labels are different lengths, now I can´t figure out how to do this, any help would be appreciated!
If I use x on x-axis, in real Dataset my prediction regression with CI won´t fit anymore. Here are the Plots from my Dataset 1: with scaled values (x.s): enter image description here and 2: If I use x instead of x.s on x-axis enter image description here