简体   繁体   English

如何将散点图矩阵转换为R Plotly

[英]How to convert scatterplot matrix into R Plotly

Hi i am using pairs() function. 嗨,我正在使用Pairs()函数。

png(file = matrixoutput, width=610, height=360)
pairs(df.log[smp,],col=mdl.km$cluster[smp],pch=16)
dev.off()

it produces the following image ... 它产生以下图像... 在此处输入图片说明

How can i convert into R plotly? 我如何将其转换为R?

library(jsonlite)
library(base64enc)
library(plotly)
dataset <- "C:\\Users\\qaise\\Desktop\\markDown\\Twittersmalldata.csv"
samplesize <- 500
clusters <-20
plotlyoutput <- "C:\\Users\\qaise\\Desktop\\markDown\\index.html"
matrixoutput <- "C:\\Users\\qaise\\Desktop\\markDown\\matric.png"

set.seed(1776)

df.oq<-read.csv(dataset)
df.oq$rratio<-(1+df.oq$followers_count)/(1+df.oq$friends_count)
names<c("followers_count","friends_count","statuses_count",
"favourites_count","list_count","rratio")
df.simp<-df.oq[,names]
df.simp<-df.simp[complete.cases(df.simp),]
df.log<-log(df.simp[,c(names)]+1)
df.log$rratio<-log(df.simp$rratio)

###
df.prec<-df.simp
for (nm in c("followers_count","friends_count","statuses_count","rratio")) {
F<-ecdf(df.simp[,nm])
df.prec[,nm]<-F(df.simp[,nm])
 }

### UI NOTE: Allow the user to select clisters from 3 - 20 
### UI NOTE: put the value of that in variable num.clusters
num.culsters <- clusters
mdl.km<-kmeans(df.log, num.culsters)
### UI NOTE: Allow the user to set sample size of values 100, 250, 500, 
1000, 2000
### UI NOTE: put the value of that in variable sample.size
sample.size <- samplesize
sample.size <- min(nrow(df.log),sample.size)
smp<-sample(nrow(df.log),size=1000)


### Matrixplot of the data
png(file = matrixoutput, width=610, height=360)
pairs(df.log[smp,],col=mdl.km$cluster[smp],pch=16)
dev.off()
require(GGally)
require(plotly)
data(tips, package="reshape")

p <- ggpairs(data=tips, # data.frame with variables
             columns=1:3, # columns to plot, default to all.
             title="tips data", # title of the plot
             colour = "sex") # aesthetics, ggplot2 style

ggplotly(p)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM