title of th graph and y axis label
Title
Question
even after entering the code i am unable to get the title of the graph and the label to y axis
R Introduction-to-ggplot2 03-04 min 50-60 sec
Answers:
For "plot()" function kindly refer to the following example for adding title and label -
plot(1:10, main = "Example plot", xlab = "X values", ylab = "Y values")
For "ggplot()" function kindly refer to the following for the same -
library(ggplot2)
ggplot(as.data.frame(matrix(1:20,nrow = 10,ncol = 2))) + geom_point(aes(x=V1,y=V2))+labs(x="X label", y="Y label", title="Plot title")
ggplot(as.data.frame(matrix(1:20,nrow = 10,ncol = 2))) + geom_point(aes(x=V1,y=V2))+labs(x="X label", y="Y label", title="Plot title")
In the "plot()" function, parameters "xlab", "ylab" and "main" are used to add axis labels and title respectively, whereas in "ggplot()" we obtain labels and title by making use of "labs()" function as shown above.
Login to add comment