全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 R语言论坛
2962 1
2015-11-26
为了使用layout 然后在Y坐标上添加个频率图,怎么样实现呢??
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2015-11-29 06:32:40
library(ggplot2)
library(gridExtra)

data1 <- diamonds
detrend <- lm(log(price)~log(carat) ,data=data1)
data1$lprice2 <- resid(detrend)

empty <- ggplot()
empty <- empty + geom_point(aes(1,1), colour="white")
empty <- empty + theme(axis.ticks=element_blank(),
                       panel.background=element_blank(),
                       axis.text.x=element_blank(),
                       axis.text.y=element_blank(),           
                       axis.title.x=element_blank(),
                       axis.title.y=element_blank(),
                       panel.grid=element_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))
hist_left <- hist_left + geom_histogram(aes(y = ..density..))
hist_left <- hist_left + labs(x=NULL, y=NULL, title=NULL)
hist_left <- hist_left + theme(legend.position = "none")

hist_bottom <- ggplot(data1, aes(x=carat, fill=color))
hist_bottom <- hist_bottom + geom_histogram()
hist_bottom <- hist_bottom + theme(legend.position = "none")

grid.arrange(arrangeGrob(hist_left + coord_flip(), scatter, ncol=2, widths=c(1,3)),
             arrangeGrob(empty, hist_bottom, ncol=2, widths=c(1,3)),
             heights=c(3,1))
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群