使用晶格将边际直方图(或箱线图)添加到xyplot [英] Adding marginal histograms (or boxplots) to xyplot using lattice

查看:109
本文介绍了使用晶格将边际直方图(或箱线图)添加到xyplot的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

类似于这个问题,我想添加一点使用latticexyplotdensityplot的直方图或箱线图.有没有办法用这些图代替右轴和/或上轴?

Similar to this question, I'd like to to add marginal histograms or boxplots to a xyplot or densityplot using lattice. Is there a way to replace the right and/or top axes with these plots instead?

类似的东西:

library(lattice)
x <- rnorm(100)
y <- rnorm(100)
xyplot(x~y, 
       x.top  = histogram(~x), # desired 
       y.right = bwplot(~y)    # desired
       )

我该怎么办?

推荐答案

ggplot2ggExtra结合使用是可行的.

Using ggplot2 with ggExtra works.

library(ggplot2)
library(ggExtra)

p <- ggplot(cars, aes_string('speed', 'dist')) +
  geom_point() + theme_bw(15)

ggExtra::ggMarginal(
  p,
  type = 'boxplot',
  margins = 'both',
  size = 5,
  color = "black",
  fill  = "darkgrey"
)

请参阅: https://daattali.com/shiny/ggExtra-ggMarginal-demo/

这篇关于使用晶格将边际直方图(或箱线图)添加到xyplot的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆