To add x-axis and y-axis labels in ggplot2, you can use the following methods:
Using xlab and ylab Functions:
library("Sleuth2")
library("ggplot2")
ggplot(ex1221, aes(Density, Discharge)) +
geom_point(aes(size=NO3)) +
scale_size_area() +
xlab("X-label") +
ylab("Y-label") +
ggtitle("Weighted Scatterplot of Density (people/km^
2) vs. Discharge and Nitrogen Levels (PPM)")
Using scale_x_continuous and scale_y_continuous:
ggplot(ex1221, aes(Density, Discharge)) +
geom_point(aes(size=NO3)) +
scale_size_area() +
scale_x_continuous("X-label") +
scale_y_continuous("Y-label") +
ggtitle("Weighted Scatterplot of Density (people/km^
2) vs. Discharge and Nitrogen Levels (PPM)")
Using labs Function:
ggplot(ex1221, aes(Density, Discharge)) +
geom_point(aes(size=NO3)) +
scale_size_area() +
labs(size= "Nitrogen",
x = "X-label",
y = "Y-label",
title = "Weighted Scatterplot of Density (people/km^
2) vs. Discharge and Nitrogen Levels (PPM)")
Output: