样本数据:
### Data
df <- data.frame(year = seq(as.Date("1998/1/1"), as.Date("2012/1/1"), "years"),
ton = sample(200:500, 15, replace = TRUE),
trend = sample(50:100, 15, replace = TRUE),
count = sample(100:200, 15, replace = TRUE))
### Load the needed libraries
library(ggplot2)
library(scales)
library(grid)
library(gridExtra)
### Make a plot
plot1 <- ggplot(data = df, aes(x = year, y = ton)) + geom_bar(stat = "identity") +
scale_x_date(breaks = df$year, labels = date_format("%Y")) +
theme_bw()
plot2 <- ggplot(data = df, aes(x = year, y = trend)) + …Run Code Online (Sandbox Code Playgroud)