Write R code using ggplot2 to create a scatter plot for the data frame sales with month on the x-axis and revenue on the y-axis.
ggplot2
is a powerful R package for creating elegant and customizable visualizations. It uses a layered approach: you start with a dataset and map variables to visual properties like axes, colors, or shapes.
library(ggplot2)
# Sample data
df <- data.frame(
height = c(150, 160, 170, 180, 190),
weight = c(55, 60, 65, 70, 75)
)
# Create a scatter plot
ggplot(df, aes(x = height, y = weight)) +
geom_point()
# Sample data
time <- 1:5
value <- c(10, 12, 15, 18, 20)
df_line <- data.frame(time, value)
# Create a line plot
ggplot(df_line, aes(x = time, y = value)) +
geom_line()
These examples show how to quickly visualize relationships between variables using points or lines.