首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为ggplot2生成的多个地块添加标题和格式化Y轴标签

为ggplot2生成的多个地块添加标题和格式化Y轴标签
EN

Stack Overflow用户
提问于 2017-04-11 20:43:52
回答 1查看 1.2K关注 0票数 0

我有一个用ggplot2生成的包含10个散点图的多点图。我用来创建图的代码已经从这里删除了,我的问题是我想为每个散点图添加不同的标题,例如,图1的标题可以是"plot 1",而plot 2的标题可以是"plot 2“,依此类推。我还想将所有地块的标签从当前标签"Y“更改为"purchases”。

EN

回答 1

Stack Overflow用户

发布于 2017-04-11 20:52:48

只需创建您的图,并按照您引用的代码分别为每个图命名。然后使用gridExtra包进行安排。标签做标题,ylab函数可以用于y标签。

代码语言:javascript
复制
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)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43346277

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档