The way i am going to tell you, will allow you to change the labels of legend, axis, title etc with a single formula and you don't need to use memorise multiple formulas. This will not affect the font style or the design of the labels/ text of titles and axis.
I am giving the complete answer of the question below.
library(ggplot2)
rating <- c(rnorm(200), rnorm(200, mean=.8))
cond <-factor(rep(c("A", "B"), each = 200))
df <- data.frame(cond,rating
)
k<- ggplot(data=df, aes(x=rating, fill=cond))+
geom_density(alpha = .3) +
xlab("NEW RATING TITLE") +
ylab("NEW DENSITY TITLE")
# to change the cond to a different label
k$labels$fill="New Legend Title"
# to change the axis titles
k$labels$y="Y Axis"
k$labels$x="X Axis"
k
I have stored the ggplot output in a variable "k". You can name it anything you like. Later I have used
k$labels$fill ="New Legend Title"
to change the legend. "fill" is used for those labels which shows different colours. If you have labels that shows sizes like 1 point represent 100, other point 200 etc then you can use this code like this-
k$labels$size ="Size of points"
and it will change that label title.
labs(fill="xyz")
should dogeom_
statements, I recommend the answer at stackoverflow.com/a/38485985/1169233, it's the only one that worked for me.