我使用grid.arrange在2个冒号上排列了一系列情节(超过10个)。由于它们都具有相同的x轴标签,因此我只为最后一个数组绘制x轴标签。但是,最后一个数组的绘图部分被压缩并缩小了
以下是此问题的可重现示例:
source("http://www.openintro.org/stat/data/arbuthnot.R")
library(ggplot2)
library(reshape2)
library(gridExtra)
names(arbuthnot) <- c("Year", "Men", "Women")
arbuthnot.melt <- melt(arbuthnot, id.vars = 'Year', variable.name = 'Sex',
value.name = 'Rate')
p1 <- ggplot(arbuthnot.melt, aes(x = Year, y = Rate, shape = Sex, color = Sex, linetype = Sex))+
geom_line() + scale_color_manual(values = c("Women" = '#ff00ff','Men' = '#3399ff')) +
scale_linetype_manual(values = c('Women' = 'solid', 'Men' = 'dotted')) +
theme (axis.text.x=element_blank(),axis.title.x=element_blank())
p2 <- ggplot(arbuthnot.melt, aes(x = Year, y = Rate, shape = Sex, color = Sex, linetype = Sex))+
geom_line() + scale_color_manual(values = c("Women" = '#ff00ff','Men' = '#3399ff')) +
scale_linetype_manual(values = c('Women' = 'solid', 'Men' = 'dotted')) +
theme (axis.text.x=element_blank(),axis.title.x=element_blank())
p3 <- ggplot(arbuthnot.melt, aes(x = Year, y = Rate, shape = Sex, color = Sex, linetype = Sex))+
geom_line() + scale_color_manual(values = c("Women" = '#ff00ff','Men' = '#3399ff')) +
scale_linetype_manual(values = c('Women' = 'solid', 'Men' = 'dotted')) +
scale_x_continuous(expand = c(0, 0), labels=c("FSSFDFSDSDF", "ASD","QDDZXCC","QDDZXCC","QDDZXCC")) +
theme(axis.text.x = element_text(hjust = 1, angle=90))
p4 <- ggplot(arbuthnot.melt, aes(x = Year, y = Rate, shape = Sex, color = Sex, linetype = Sex))+
geom_line() + scale_color_manual(values = c("Women" = '#ff00ff','Men' = '#3399ff')) +
scale_linetype_manual(values = c('Women' = 'solid', 'Men' = 'dotted')) +
scale_x_continuous(expand = c(0, 0), labels=c("FSSFDFSDSDF", "ASD","QDDZXCC","QDDZXCC","QDDZXCC")) +
theme(axis.text.x = element_text(hjust = 1, angle=90))
grid.arrange(p1, p2, p3, p4, ncol=2)
是否可以将绘图格式标准化,而不考虑它们是否拥有图例?我的情况是,甚至不可能阅读最后两个情节的内容......