我正在使用ggplot并且有两个图表,我希望彼此叠加显示.我使用grid.arrangegridExtra来堆叠它们.问题是,无论轴标签如何,我都希望图形的左边缘与右边缘对齐.(问题出现是因为一个图的标签很短而另一个图很长).
问题:
我该怎么做?我没有和grid.arrange结婚,但ggplot2是必须的.
我尝试了什么:
我尝试使用宽度和高度以及ncol和nrow来制作2 x 2网格并将视觉效果放在相对的角落然后玩宽度但我无法在对角处获得视觉效果.
require(ggplot2);require(gridExtra)
A <- ggplot(CO2, aes(x=Plant)) + geom_bar() +coord_flip()
B <- ggplot(CO2, aes(x=Type)) + geom_bar() +coord_flip()
grid.arrange(A, B, ncol=1)
Run Code Online (Sandbox Code Playgroud)

我正在使用网格包来放置我用ggplot2制作的图表:
library(ggplot2)
library(grid)
Layout <- grid.layout(nrow = 4, ncol = 4,
widths = unit(1, "null"),
heights = unit(c(0.4, 0.8, 1.2, 1.2), c("null", "null", "null")))
grid.show.layout(Layout)
plot1 = ggplot(diamonds, aes(clarity, fill = color)) +
geom_bar() +
facet_wrap(~cut, nrow = 1)
print(plot1 + theme(legend.position = "none"),
vp = viewport(layout.pos.row = 3, layout.pos.col = 1:4))
Run Code Online (Sandbox Code Playgroud)
问题是我想把图放在第三行(3,1) - (3,4)并将图例放在(4,4)位置.不幸的是,我真的找不到创建图例变量的方法.我在网上搜索,我得到的最接近的是使用旧的,
+ opts(keep = "legend_box")但已被弃用.
我想我有一个棘手的案子.我正在及时绘制进化植物疾病水平,使用geom_raster:x和y是任意场坐标,z是在几个时间点测量的疾病水平,我希望将每个日期绘制在不同的方面.到目前为止,没问题.下面是模拟数据集和代码:
library(ggplot2)
data <- data_frame(month=factor(rep(c("march","april","may","june"), each=100), levels=c("march","april","may","june")),
x=rep(rep(1:10, each=10), 4),
y=rep(rep(1:10, 10), 4),
z=c(rnorm(100, 0.5, 1), rnorm(100, 3, 1.5), rnorm(100, 6, 2), rnorm(100, 9, 1)))
ggplot(data, aes(x=x, y=y, fill=z)) +
geom_raster(color="white") +
scale_fill_gradient2(low="white", mid=mean(range(dat$z)), high="red") +
scale_x_discrete(limit=1:10, expand = c(0, 0)) +
scale_y_discrete(limit=1:10, expand = c(0, 0)) +
coord_equal() +
facet_wrap(~month)
Run Code Online (Sandbox Code Playgroud)
但我真正喜欢的是让每个小平面以一定角度(例如15°)旋转,以反映我的场不是完全根据北方定向的事实(即,顶部不是北方,而是底部不是南方).ggplot2或任何与网格相关的工具是否有可能自动执行此操作?即使是将各个方面保存到图像,旋转它们以及在新页面上打印旋转图像的自动方式也足以满足我的需求.这是我想要获得的图像示例(在图像编辑器中旋转15°的面):http:
//imgur.com/RYJ3EaR