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

时间:2017-08-03 07:44:43

标签: r plotly scatter-plot

您好我正在使用pairs()函数。

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

它产生以下图像...... enter image description here

我怎样才能将R转换为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()

1 个答案:

答案 0 :(得分:2)

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)
相关问题