R语言怎么给坐标轴添加表示分组的线段
本篇内容主要讲解“R语言怎么给坐标轴添加表示分组的线段”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“R语言怎么给坐标轴添加表示分组的线段”吧!
创新互联是一家专注于成都做网站、网站制作与策划设计,建湖网站建设哪家好?创新互联做网站,专注于网站建设十余年,网设计领域的专业建站公司;建站业务涵盖:建湖等地区。建湖做网站价格咨询:028-86922220

df<-data.frame(A=1:3,B=1:3)
library(ggplot2)
ggplot(df,aes(x=A,y=B))+
geom_col()+
annotate(geom = "text",x=1,y=0,label="AAA",vjust=3)

可以看到AAA这个文本大部分都被盖住了,可以看下加上coord_cartesian(clip = "off")
函数的效果
df<-data.frame(A=1:3,B=1:3)
library(ggplot2)
ggplot(df,aes(x=A,y=B))+
geom_col()+
annotate(geom = "text",x=1,y=0,label="AAA",vjust=3)+
coord_cartesian(clip = "off")

首先是气泡图
set.seed("20210329")
df<-data.frame(x=rep(letters[1:6]),
y=c(rep("A",6),rep("B",6)),
value=sample(1:100,12))
df
ggplot(data=df,aes(x=x,y=y))+
geom_point(aes(size=value),
color="red",
alpha=0.5,
show.legend = F)+
scale_size_continuous(range = c(3,20))+
theme_bw()

ggplot(data=df,aes(x=x,y=y))+
geom_point(aes(size=value),
color="red",
alpha=0.5,
show.legend = F)+
scale_size_continuous(range = c(3,20))+
theme_bw()+
geom_segment(x=1,xend=3,y=2.7,yend=2.7)+
geom_segment(x=4,xend=6,y=2.7,yend=2.7)+
geom_segment(x=1,xend=1,y=2.65,yend=2.7)+
geom_segment(x=3,xend=3,y=2.65,yend=2.7)+
geom_segment(x=4,xend=4,y=2.65,yend=2.7)+
geom_segment(x=6,xend=6,y=2.65,yend=2.7)+
annotate(geom="text",x=2,y=2,label="First",vjust=-16)+
annotate(geom="text",x=5,y=2,label="Second",vjust=-16)+
coord_cartesian(clip = "off")+
theme(plot.margin = unit(c(2,0.2,0.2,0.2),'cm'))

到此,相信大家对“R语言怎么给坐标轴添加表示分组的线段”有了更深的了解,不妨来实际操作一番吧!这里是创新互联网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!
本文名称:R语言怎么给坐标轴添加表示分组的线段
分享地址:http://pcwzsj.com/article/gpppch.html