R语言绘制不同调色板的正方形气球图
library(ggplot2)
library(RColorBrewer)
library(ggrepel)
attach(mtcars)
#--------------------------(d) 方块状的气泡图--------------------------------------------------
ggplot(mtcars, aes(wt,mpg))+
geom_point(aes(size=disp,fill=disp),shape=22,colour="black",alpha=0.8)+
scale_fill_gradient2(low=brewer.pal(7,"Set1")[2],high=brewer.pal(7,"Set1")[1],
midpoint = mean(mtcars$disp))+
scale_size_area(max_size=12)+
guides(fill = guide_legend((title="Value")),
size = guide_legend((title="Value")))+
theme(
text=element_text(size=15,color="black"),
plot.title=element_text(size=15,family="myfont",face="bold.italic",color="black")#,
#legend.position=c(0.9,0.05)
)

#--------------------------(d) 方块状的气泡图--------------------------------------------------
ggplot(mtcars, aes(wt,mpg))+
geom_point(aes(size=disp,fill=disp),shape=22,colour="black",alpha=0.8)+
scale_fill_gradient2(low=brewer.pal(7,"Set2")[2],high=brewer.pal(7,"Set2")[1],
midpoint = mean(mtcars$disp))+
scale_size_area(max_size=12)+
guides(fill = guide_legend((title="Value")),
size = guide_legend((title="Value")))+
theme(
text=element_text(size=15,color="black"),
plot.title=element_text(size=15,family="myfont",face="bold.italic",color="black")#,
#legend.position=c(0.9,0.05)
)
'
#--------------------------(d) 方块状的气泡图--------------------------------------------------
ggplot(mtcars, aes(wt,mpg))+
geom_point(aes(size=disp,fill=disp),shape=22,colour="black",alpha=0.8)+
scale_fill_gradient2(low=brewer.pal(7,"Set3")[2],high=brewer.pal(7,"Set3")[1],
midpoint = mean(mtcars$disp))+
scale_size_area(max_size=12)+
guides(fill = guide_legend((title="Value")),
size = guide_legend((title="Value")))+
theme(
text=element_text(size=15,color="black"),
plot.title=element_text(size=15,family="myfont",face="bold.italic",color="black")#,
#legend.position=c(0.9,0.05)
)

#--------------------------(d) 方块状的气泡图--------------------------------------------------
ggplot(mtcars, aes(wt,mpg))+
geom_point(aes(size=disp,fill=disp),shape=22,colour="black",alpha=0.8)+
scale_fill_gradient2(low=brewer.pal(7,"Pastel1")[2],high=brewer.pal(7,"Pastel1")[1],
midpoint = mean(mtcars$disp))+
scale_size_area(max_size=12)+
guides(fill = guide_legend((title="Value")),
size = guide_legend((title="Value")))+
theme(
text=element_text(size=15,color="black"),
plot.title=element_text(size=15,family="myfont",face="bold.italic",color="black")#,
#legend.position=c(0.9,0.05)
)

#--------------------------(d) 方块状的气泡图--------------------------------------------------
ggplot(mtcars, aes(wt,mpg))+
geom_point(aes(size=disp,fill=disp),shape=22,colour="black",alpha=0.8)+
scale_fill_gradient2(low=brewer.pal(7,"Pastel2")[2],high=brewer.pal(7,"Pastel2")[1],
midpoint = mean(mtcars$disp))+
scale_size_area(max_size=12)+
guides(fill = guide_legend((title="Value")),
size = guide_legend((title="Value")))+
theme(
text=element_text(size=15,color="black"),
plot.title=element_text(size=15,family="myfont",face="bold.italic",color="black")#,
#legend.position=c(0.9,0.05)
)

#--------------------------(d) 方块状的气泡图--------------------------------------------------
ggplot(mtcars, aes(wt,mpg))+
geom_point(aes(size=disp,fill=disp),shape=22,colour="black",alpha=0.8)+
scale_fill_gradient2(low=brewer.pal(7,"Paired")[2],high=brewer.pal(7,"Paired")[1],
midpoint = mean(mtcars$disp))+
scale_size_area(max_size=12)+
guides(fill = guide_legend((title="Value")),
size = guide_legend((title="Value")))+
theme(
text=element_text(size=15,color="black"),
plot.title=element_text(size=15,family="myfont",face="bold.italic",color="black")#,
#legend.position=c(0.9,0.05)
)

#--------------------------(d) 方块状的气泡图--------------------------------------------------
ggplot(mtcars, aes(wt,mpg))+
geom_point(aes(size=disp,fill=disp),shape=22,colour="black",alpha=0.8)+
scale_fill_gradient2(low=brewer.pal(7,"Dark2")[2],high=brewer.pal(7,"Dark2")[1],
midpoint = mean(mtcars$disp))+
scale_size_area(max_size=12)+
guides(fill = guide_legend((title="Value")),
size = guide_legend((title="Value")))+
theme(
text=element_text(size=15,color="black"),
plot.title=element_text(size=15,family="myfont",face="bold.italic",color="black")#,
#legend.position=c(0.9,0.05)
)

#--------------------------(d) 方块状的气泡图--------------------------------------------------
ggplot(mtcars, aes(wt,mpg))+
geom_point(aes(size=disp,fill=disp),shape=22,colour="black",alpha=0.8)+
scale_fill_gradient2(low=brewer.pal(7,"Accent")[2],high=brewer.pal(7,"Accent")[1],
midpoint = mean(mtcars$disp))+
scale_size_area(max_size=12)+
guides(fill = guide_legend((title="Value")),
size = guide_legend((title="Value")))+
theme(
text=element_text(size=15,color="black"),
plot.title=element_text(size=15,family="myfont",face="bold.italic",color="black")#,
#legend.position=c(0.9,0.05)
)

#--------------------------(d) 方块状的气泡图--------------------------------------------------
ggplot(mtcars, aes(wt,mpg))+
geom_point(aes(size=disp,fill=disp),shape=22,colour="black",alpha=0.8)+
scale_fill_gradient2(low=brewer.pal(7,"Spectral")[2],high=brewer.pal(7,"Spectral")[1],
midpoint = mean(mtcars$disp))+
scale_size_area(max_size=12)+
guides(fill = guide_legend((title="Value")),
size = guide_legend((title="Value")))+
theme(
text=element_text(size=15,color="black"),
plot.title=element_text(size=15,family="myfont",face="bold.italic",color="black")#,
#legend.position=c(0.9,0.05)
)

开发工具:Alt+A微信截屏工具与RStudio
- 点赞
- 收藏
- 关注作者
评论(0)