我有一个用ggplot2生成的包含10个散点图的多点图。我用来创建图的代码已经从这里删除了,我的问题是我想为每个散点图添加不同的标题,例如,图1的标题可以是"plot 1",而plot 2的标题可以是"plot 2“,依此类推。我还想将所有地块的标签从当前标签"Y“更改为"purchases”。
发布于 2017-04-11 20:52:48
只需创建您的图,并按照您引用的代码分别为每个图命名。然后使用gridExtra包进行安排。标签做标题,ylab函数可以用于y标签。
library(ggplot2)
# This example uses the ChickWeight dataset, which comes with ggplot2
# First plot
p1 <- ggplot(ChickWeight, aes(x=Time, y=weight, colour=Diet, group=Chick)) +
geom_line() +
ggtitle("Growth curve for individual chicks")
# Second plot
p2 <- ggplot(ChickWeight, aes(x=Time, y=weight, colour=Diet)) +
geom_point(alpha=.3) +
geom_smooth(alpha=.2, size=1) +
ggtitle("Fitted growth curve per diet")
# Third plot
p3 <- ggplot(subset(ChickWeight, Time==21), aes(x=weight, colour=Diet)) +
geom_density() +
ggtitle("Final weight, by diet")
# Fourth plot
p4 <- ggplot(subset(ChickWeight, Time==21), aes(x=weight, fill=Diet)) +
geom_histogram(colour="black", binwidth=50) +
facet_grid(Diet ~ .) +
ggtitle("Final weight, by diet") +
theme(legend.position="none") # No legend (redundant in this graph)
require(gridExtra)
grid.arrange(p1, p2, p3, p4, nrow = 2)https://stackoverflow.com/questions/43346277
复制相似问题