我試圖使用ggplot在一個窗口框中對齊柱圖和線圖的x軸。這是我正在嘗試使用的假數據。使用ggplot對齊盒圖和線圖的x軸
library(ggplot2)
library(gridExtra)
m <- as.data.frame(matrix(0, ncol = 2, nrow = 27))
colnames(m) <- c("x", "y")
for(i in 1:nrow(m))
{
m$x[i] <- i
m$y[i] <- ((i*2) + 3)
}
My_plot <- (ggplot(data = m, aes(x = x, y = y)) + theme_bw())
Line_plot <- My_plot + geom_line()
Bar_plot <- My_plot + geom_bar(stat = "identity")
grid.arrange(Line_plot, Bar_plot)
謝謝你的幫助。
請問這種方法也可用於核絲工作使用高度調高每個地塊的y軸? –
我想象。試試看? –
@JakeConway是的,它的確如此。但看到這個答案更簡潔的方法:http://stackoverflow.com/questions/30492434/show-ggplot2-title-without-reserving-space-for-it/30492601#30492601 –