R语言画图1

ggplot(Express, mapping = aes(x=X, y=Y,col = clustering))+geom_point(size = 0.5,alpha=0.7)+scale_color_gradient(‘clustering’, low = “red”, high = “blue”)
Express c l u s t e r i n g = f a c t o r ( E x p r e s s clustering=factor(Express clustering=factor(Expressclustering)
#Express$clustering表示获取Express中的cluster列 并转化其类型
#将聚类编号的整型int改成factor类型,才能画出不同的颜色
#因子(factor)数据的类型分为名义型、有序型和连续型,其中名义型和有序型被称为因子,默认因子排序是按照字符排序
ggplot(Express,aes(x=X, y=Y,col = clustering))+geom_point()
K-means聚类画图
site=“https://mirrors.tuna.tsinghua.edu.cn/CRAN”
package_list = c(“factoextra”,“cluster”)
for(p in package_list){
if(!suppressWarnings(suppressMessages(require(p, character.only = TRUE, quietly = TRUE, warn.conflicts = FALSE)))){
install.packages(p, repos=site)
suppressWarnings(suppressMessages(library(p, character.only = TRUE, quietly = TRUE, warn.conflicts = FALSE)))
}
}

##kmeans聚类
#km.res = kmeans(Express, 20)
#fviz_cluster(km.res,Express)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值