绘制单个输出旁边的图形

时间:2017-08-21 10:17:01

标签: r ggplot2

我有一个像这个数据框的数据集:

structure(list(year = c(2001L, 2002L, 2003L, 2004L, 2005L, 2006L, 
2007L, 2001L, 2002L, 2003L, 2004L, 2005L, 2006L, 2007L, 2001L, 
2002L, 2003L, 2004L, 2005L, 2006L, 2007L, 2001L, 2002L, 2003L, 
2004L, 2005L, 2006L, 2007L, 2001L, 2002L, 2003L, 2004L, 2005L, 
2006L, 2007L, 2001L, 2002L, 2003L, 2004L, 2005L, 2006L, 2007L
), volume = c(21L, 44L, 37L, 23L, 46L, 21L, 69L, 21L, 44L, 37L, 
23L, 46L, 21L, 69L, 21L, 44L, 37L, 23L, 46L, 21L, 69L, 21L, 44L, 
37L, 23L, 46L, 21L, 69L, 21L, 44L, 37L, 23L, 46L, 21L, 69L, 21L, 
44L, 37L, 23L, 46L, 21L, 69L), stock = structure(c(1L, 1L, 1L, 
1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 
6L, 6L, 6L, 6L, 6L, 6L, 6L), .Label = c("stock1", "stock2", "stock3", 
"stock4", "stock5", "stock6"), class = "factor")), .Names = c("year", 
"volume", "stock"), class = "data.frame", row.names = c(NA, -42L
))

我尝试使用this之类的输出。

我知道的事情

library(ggplot2)
p <- ggplot(df, aes(x = df$year, y = df$volume)) + geom_line(aes(color = "red")) + 
    facet_grid(stock ~ ., scales = "free_x") + theme(legend.position = left)

0 个答案:

没有答案