概述
library(ggplot2)
library(RColorBrewer)
#-----------------------------(b) 带透明度设置的散点图------------------------------
mydata<-read.csv("HighDensity_Scatter_Data.csv",stringsAsFactors=FALSE)
ggplot(data = mydata, aes(x,y)) +
geom_point( colour="black",alpha=0.1)+
labs(x = "Axis X",y="Axis Y")+
theme(
text=element_text(size=15,color="black"),
plot.title=element_text(size=15,family="myfont",face="bold.italic",hjust=.5,color="black"),
legend.position="none"
)
kmeansResult<- kmeans(mydata, 2, nstart = 20)
mydata$cluster <- as.factor(kmeansResult$cluster)
ggplot(data = mydata, aes(x,y,color=cluster)) +
geom_point( alpha=0.2)+
scale_color_manual(values=c("#00AFBB", "#FC4E07"))+
labs(x = "Axis X",y="Axis Y")+
theme(
text=element_text(size=15,color="black"),
plot.title=element_text(size=15,family="myfont",face="bold.italic",color="black"),
legend.background=element_blank(),
legend.position=c(0.85,0.15)
)
kmeansResult<- kmeans(mydata, 2, nstart = 20)
mydata$cluster <- as.factor(kmeansResult$cluster)
ggplot(data = mydata, aes(x,y,color=cluster)) +
geom_point( alpha=0.2)+
scale_color_manual(values=c("#00FFFF", "#7FFFD4"))+
labs(x = "Axis X",y="Axis Y")+
theme(
text=element_text(size=15,color="black"),
plot.title=element_text(size=15,family="myfont",face="bold.italic",color="black"),
legend.background=element_blank(),
legend.position=c(0.85,0.15)
)
kmeansResult<- kmeans(mydata, 2, nstart = 20)
mydata$cluster <- as.factor(kmeansResult$cluster)
ggplot(data = mydata, aes(x,y,color=cluster)) +
geom_point( alpha=0.2)+
scale_color_manual(values=c("#8A2BE2", "#A52A2A"))+
labs(x = "Axis X",y="Axis Y")+
theme(
text=element_text(size=15,color="black"),
plot.title=element_text(size=15,family="myfont",face="bold.italic",color="black"),
legend.background=element_blank(),
legend.position=c(0.85,0.15)
)
kmeansResult<- kmeans(mydata, 2, nstart = 20)
mydata$cluster <- as.factor(kmeansResult$cluster)
ggplot(data = mydata, aes(x,y,color=cluster)) +
geom_point( alpha=0.2)+
scale_color_manual(values=c("#DEB887", "#5F9EA0"))+
labs(x = "Axis X",y="Axis Y")+
theme(
text=element_text(size=15,color="black"),
plot.title=element_text(size=15,family="myfont",face="bold.italic",color="black"),
legend.background=element_blank(),
legend.position=c(0.85,0.15)
)
kmeansResult<- kmeans(mydata, 2, nstart = 20)
mydata$cluster <- as.factor(kmeansResult$cluster)
ggplot(data = mydata, aes(x,y,color=cluster)) +
geom_point( alpha=0.2)+
scale_color_manual(values=c("#7FFF00", "#D2691E"))+
labs(x = "Axis X",y="Axis Y")+
theme(
text=element_text(size=15,color="black"),
plot.title=element_text(size=15,family="myfont",face="bold.italic",color="black"),
legend.background=element_blank(),
legend.position=c(0.85,0.15)
)
kmeansResult<- kmeans(mydata, 2, nstart = 20)
mydata$cluster <- as.factor(kmeansResult$cluster)
ggplot(data = mydata, aes(x,y,color=cluster)) +
geom_point( alpha=0.2)+
scale_color_manual(values=c("#FF7F50", "#6495ED"))+
labs(x = "Axis X",y="Axis Y")+
theme(
text=element_text(size=15,color="black"),
plot.title=element_text(size=15,family="myfont",face="bold.italic",color="black"),
legend.background=element_blank(),
legend.position=c(0.85,0.15)
)
ggplot(data = mydata, aes(x,y,color=cluster)) +
geom_point (alpha=0.2)+
# 绘制透明度为0.2 的散点图
stat_ellipse(aes(x=x,y=y,fill= cluster), geom="polygon", level=0.95, alpha=0.2) +
#绘制椭圆标定不同类别,如果省略该语句,则绘制图3-1-7(c)
scale_color_manual(values=c("#00AFBB","#FC4E07")) +#使用不同颜色标定不同数据类别
scale_fill_manual(values=c("#00AFBB","#FC4E07"))+ #使用不同颜色标定不同椭类别
labs(x = "Axis X",y="Axis Y")+
theme(
text=element_text(size=15,color="black"),
plot.title=element_text(size=15,family="myfont",face="bold.italic",color="black"),
legend.background=element_blank(),
legend.position=c(0.85,0.15)
)
开发工具:RStudio与微信Alt+A截屏工具
最后
以上就是温柔棒棒糖为你收集整理的R语言绘制高密度散点图的全部内容,希望文章能够帮你解决R语言绘制高密度散点图所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复