如何使用R ggpairs和plotly获得单个Interactive Correlation散点图矩阵三角形

时间:2018-05-31 14:40:44

标签: r plotly scatter-plot ggplotly ggally

我试图得到一个约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)

示例1

包含两个三角形的矩阵看起来像enter image description here我收到以下警告

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  

示例2

然而,当我改为只查看矩阵的一个三角形时,这就是它给我的东西,并带有与上面相同的警告:

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)

enter image description here

目的

但如果我只使用标准(非交互式)ggpairs输出它看起来很不错:enter image description here这次我只得到Warning messages: 1: Groups with fewer than two data points have been dropped.如果有人会很棒对于如何制作ploty子图片有任何想法,就像标准ggpairs示例一样,以便启用交互性。

0 个答案:

没有答案