library(ggplot2)
# Create a sample plot
p <- ggplot(data = mtcars, aes(x = disp, y = mpg)) +
geom_point() +
labs(title = "Scatter Plot\nCar Displacement vs. MPG")
# Modify the plot.title element
p + theme(plot.title = element_text(lineheight = 1.2))
# Create a sample plot
p <- ggplot(data = mtcars, aes(x = disp, y = mpg)) +
geom_point() +
labs(title = expression("Scatter Plot" ~ atop("Car Displacement vs. MPG")))
# Render the plot
p
# Create a sample plot
p <- ggplot(data = mtcars, aes(x = disp, y = mpg)) +
geom_point()
# Set the title using ggtitle
p + ggtitle("Scatter Plot\nCar Displacement vs. MPG")
library(gridExtra)
# Create two sample plots
p1 <- ggplot(data = mtcars, aes(x = disp, y = mpg)) +
geom_point() +
labs(title = "Scatter Plot\nCar Displacement vs. MPG")
p2 <- ggplot(data = mtcars, aes(x = hp, y = mpg)) +
geom_point() +
labs(title = "Scatter Plot\nCar Horsepower vs. MPG")
# Arrange the plots in a grid layout
grid.arrange(p1, p2, nrow = 1)