【发布时间】:2014-10-26 10:24:55
【问题描述】:
如何创建带有左侧和底部直方图的散点图,就像下面 ggplot2 中的示例一样?
library(ggplot2)
library(gridExtra)
data1<-diamonds
detrend<-lm(log(price)~log(carat),data=data1)
data1$lprice2<-resid(detrend)
empty <- ggplot()+geom_point(aes(1,1), colour="white")+
opts(axis.ticks=theme_blank(),
panel.background=theme_blank(),
axis.text.x=theme_blank(), axis.text.y=theme_blank(),
axis.title.x=theme_blank(), axis.title.y=theme_blank())
scatter<-qplot(log(carat),lprice2,data=data1,xlab="Weight",ylab="Price Residuals",
colour=factor(color),main="Diamonds - Weight to Price by Color")
scatter<-scatter+theme(legend.position="top")
scatter<-scatter+theme(plot.title=element_text(size=20,colour="blue"))
hist_left<-ggplot(data1,aes(x=price, fill=color))+geom_histogram(aes(y = ..density..))+
theme(legend.position = "none")+coord_flip()
hist_bottom<-ggplot(data1,aes(x=carat, fill=color))+geom_histogram()
+theme(legend.position = "none")
如何使用grid.arrange来排列这些情节以及如何像图片一样翻转hist_left?
【问题讨论】:
-
谢谢!但我使用 grid.arrange(arrangeGrob(hist_left,scatter,ncol=2,widths=c(3,1)),arrangeGrob(hist_bottom,ncol=2,widths=c(3,1)), heights=c(1 ,3)) 并且不能绘制图片。
标签: r