使用ggplot时,不能在r中标记多面板图形 [英] Can't label multi-panel figure in r while using ggplot

查看:158
本文介绍了使用ggplot时,不能在r中标记多面板图形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对不起,这个问题可能很简单。我是一名程序员,虽然我很少处理图形,并且在解决这个问题之后把头发撕碎几个小时,现在是时候得到一些帮助。我使用ggplot在r中创建了一个多面板图,但在使用ggplot时,我无法找到一种在图的外部显示图标的方法。



是我想要我的代码做的:

  par(mfrow = c(1,2),pty =s, las = 1,mgp = c(2,0.4,0),tcl = -0.3)
qqnorm(rnorm(100),main =)
mtext(a,side = 3, (b = 1,= 0,cex = 1.1)
qqnorm(rnorm(100),main =)
mtext(b,side = 3,line = 1,adj = 0, cex = 1.1)

如何在地点获得这些a和b标签它们是由上面的代码创建的数字,代入这种类型的代码:

  df = data.frame(gp =因子(rep(字母[1:3],每个= 10)),y = rnorm(30))
p = ggplot(df)+ geom_point(aes(x = gp,y = y))
p2 = ggplot(df)+ geom_point(aes(x = y,y = gp))
grid.arrange(p,p2,ncol = 2)

预先感谢您的帮助!

您可以使用 ggtitle 主题

  df = data.frame(gp = factor(rep(letters [1:3],each = 10)),y = rnorm(30))
p = ggplot(df)+ geom_point(aes(x = gp,y = y))+ ggtitle('a')+ theme(plot.title = element_text(hjust = 0))
p2 = ggplot df)+ geom_point(aes(x = y,y = gp))+ ggtitle('b')+ theme(plot.title = element_text(hjust = 0))
grid.arrange(p,p2,ncol = 2)


Sorry for the possibly simple question. I'm a programmer, though I rarely deal with graphics, and after tearing my hair out for hours with this problem, it's time to get some help. I'm creating a multi-panel plot in r using ggplot, but I cannot find a way to display figure labels, outside of the figure, when using ggplot.

Here is what I want my code to do:

par(mfrow = c(1, 2), pty = "s", las = 1, mgp = c(2, 0.4, 0), tcl = -0.3)
qqnorm(rnorm(100), main = "")
mtext("a", side = 3, line = 1, adj = 0, cex = 1.1)
qqnorm(rnorm(100), main = "")
mtext("b", side = 3, line = 1, adj = 0, cex = 1.1)

How would I get those "a" and "b" labels, in the location that they are in for the figure created by the above code, into this type of code:

df = data.frame(gp = factor(rep(letters[1:3], each = 10)), y = rnorm(30))
p = ggplot(df) + geom_point(aes(x = gp, y = y))
p2 = ggplot(df) + geom_point(aes(x = y, y = gp))
grid.arrange(p, p2, ncol = 2)

Thank you in advance for your help!

解决方案

You could use ggtitle and theme:

df = data.frame(gp = factor(rep(letters[1:3], each = 10)), y = rnorm(30))
p = ggplot(df) + geom_point(aes(x = gp, y = y)) + ggtitle('a') + theme(plot.title=element_text(hjust=0))
p2 = ggplot(df) + geom_point(aes(x = y, y = gp)) + ggtitle('b') + theme(plot.title=element_text(hjust=0))
grid.arrange(p, p2, ncol = 2)

这篇关于使用ggplot时,不能在r中标记多面板图形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆