0 votes
1 view
in R Programming by (6.5k points)

How do I change the x and y labels on this graph, please?

library(Sleuth2)

library(ggplot2)

discharge<-ex1221new$Discharge

area<-ex1221new$Area

nitrogen<-ex1221new$NO3

p <- ggplot(ex1221new, aes(discharge, area), main="Point")

p + geom_point(aes(size= nitrogen)) + 

    scale_area() + 

    opts(title = expression("Weighted Scatterplot of Watershed Area vs. Discharge and Nitrogen Levels (PPM)"), 

         subtitle="n=41")

1 Answer

0 votes
by (25.3k points)

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:

image

Related questions

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...