我试图得到一个约5个变量的交互式散点图矩阵,我感兴趣的是看每个变量的观察结果如何相互关联,以及发现和识别异常值。在我看来,问题是plotly
表现得无法预测。
#sample data
sample_data <- data.frame(Class = sample(x= letters[1:15],size=50,replace = TRUE),
Sample_number = seq(1,50,by=1),
x1= rnorm(50,mean=0, sd=.5),
x2= rnorm(50,mean=0.5, sd=1.5),
x3= rnorm(50,mean=5, sd=.1),
x4= rnorm(50,mean=0, sd=3.5),
x5= rnorm(50,mean=-6, sd=.005))
#creating the standard plot
p1 <- ggpairs(data=sample_data, # data.frame with variables
columns=3:7, # columns to plot, default to all.
title=paste0("Variable Correlations"), # title of the plot
aes(color = Class, text=Sample_number),
progress = FALSE) +
theme_bw()
#creating the interactive plot
ggplotly(p1)
Warning messages:
1: Groups with fewer than two data points have been dropped.
2: Groups with fewer than two data points have been dropped.
3: Can only have one: highlight
然而,当我改为只查看矩阵的一个三角形时,这就是它给我的东西,并带有与上面相同的警告:
p2 <- ggpairs(data=sample_data, # data.frame with variables
columns=3:7, # columns to plot, default to all.
title=paste0("Variable Correlations"), # title of the plot
aes(color = Class, text=Sample_number),
uppper=list(continuous="points"),
lower="blank",
progress = FALSE)+
theme_bw()
ggplotly(p2)
但如果我只使用标准(非交互式)ggpairs
输出它看起来很不错:这次我只得到
Warning messages: 1: Groups with fewer than two data points have been dropped.
如果有人会很棒对于如何制作ploty
子图片有任何想法,就像标准ggpairs
示例一样,以便启用交互性。