切片机PowerBI由R管理

时间:2018-05-21 17:11:04

标签: r powerbi powerbi-datasource powerbi-desktop power-bi-report-server

我在PowerBI中有一个R程序,我希望在条件下通过切片器进行更改

sta5< - test.pca $ x [(m $ Obj == 5),] sta5 [1:2]

是否可以通过切片机自动更改R程序? m $ Obj应该灵活吗?

data(dataset)

head(dataset)
m <-dataset
nc <-ncol(dataset)
values <- dataset[,3:nc]
values
mean_is_0 <- sapply(values, mean) == 0
values <- values[ ! mean_is_0 ]
is.na(values) <- !values
values

mean_is_0 <- sapply(values, mean) == 0
values


for(i in 1:ncol(values)){
  values[is.na(values[,i]), i] <- mean(values[,i], na.rm = TRUE)
}  
values

test.pca <- prcomp(values,center = TRUE,scale. = TRUE)
plot(test.pca)
predict(test.pca,  newdata=tail(values, 2))
library(devtools)
library(ggbiplot)



sta5 <- test.pca$x[which(m$Obj == 5),]
   sta5[1:2]


sta4 <- test.pca$x[which(m$Obj == 4),]
sta4[1:2]
sta3 <- test.pca$x[which(m$Obj == 3),]
sta3[1:2]
sta2 <- test.pca$x[which(m$Obj == 2),]
sta2[1:2]
sta1 <- test.pca$x[which(m$Obj == 1),]
sta1[1:2]


g <- ggbiplot(test.pca, obs.scale = 1, var.scale = 1, ellipse = TRUE, 
              circle = FALSE) + geom_point(aes(x=sta5[1], y=sta5[2]), col="blue", size=4) + geom_point(aes(x=sta4[1], y=sta4[2]), col="blue", size=4)+ geom_point(aes(x=sta3[1], y=sta3[2]), col="blue", size=4)+ geom_point(aes(x=sta2[1], y=sta2[2]), col="blue", size=4)+ geom_point(aes(x=sta1[1], y=sta1[2]), col="blue", size=4) 


g <- g + scale_color_discrete(name = '')
g <- g + theme(legend.direction = 'horizontal', 
               legend.position = 'top')



print(g)

0 个答案:

没有答案