r - R 的多元图形推荐

标签 r graphics mean multivariate-testing

您能否推荐在任何可用的 R 包中使用四个变量可视化数据的最佳方法。

也就是说,我有两个分类变量(人口(12)和字符(50))和两个连续变量(100 个个体(矩阵中的行)的每个字符长度测量的平均值和变异系数)。所以它基本上是一个 12x50x100x100 维图。

有什么建议吗?

最佳答案

我会先逐个绘制变量,然后一起绘制, 从全体人口开始,逐步 将数据分成不同的组。

# Sample data
n1 <- 6   # Was: 12
n2 <- 5   # Was: 50
n3 <- 10  # Was: 100
d1 <- data.frame(
  population = rep(LETTERS[1:n1], each=n2*n3),
  character = rep(1:n2, each=n3, times=12),
  id = 1:(n1*n2*n3),
  mean = rnorm(n1*n2*n3),
  var  = rchisq(n1*n2*n3, df=5)
)
# Not used, but often useful with ggplot2
library(reshape2)
d2 <- melt(d1, id.vars=c("population","character","id"))

# Look at the first variable
library(lattice)
densityplot( ~ mean, data=d1 )
densityplot( ~ mean, groups=population, data=d1 )
densityplot( ~ mean | population, groups=character, data=d1 )

# Look at the second variable
densityplot( ~ var, data=d1 )
densityplot( ~ var, groups=population, data=d1 )
densityplot( ~ var | population, groups=character, data=d1 )

# Look at both variables
xyplot( mean ~ var, data=d1 )
xyplot( mean ~ var, groups=population, data=d1 )
xyplot( mean ~ var | population, groups=character, data=d1 )

# The plots may be more readable with lines rather than points
xyplot( 
  mean ~ var | population, groups = character, 
  data = d1, 
  panel = panel.superpose, panel.groups = panel.loess
)

关于r - R 的多元图形推荐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9393986/

相关文章:

r - 隐藏 .Rprofile 中的一些函数

r - 绘制时 Shapefile 和矢量文件不会精确重叠

r - 将数据映射到数据框中的列的更好方法?

java - 使用抽象父类(super class)生成子类的随机实例

opengl - 分割如何提高性能?

python - 如何将 PySpark Dataframe 转换为 R 可以在 DataBricks 中识别的内容?

c++ - 在程序中包含图形界面

javascript - 在 Angular 4/5/6/7 中对不同组件使用不同的样式表

python - 如何计算列 Pandas 数据框中列表的平均值

python - Python 和 Matlab 中平均频率的差异