R在重叠点geom_point之间水平增加space
R increase space horizontally between overlapping points geom_point
我有一个类似于下面的数据table:
我正在尝试绘制每周对应于每个患者的点(分类变量“数据”)(缺少一些纵向数据),但我需要增加水平轴上分类变量“数据”点之间的距离。我正在尝试使用以下代码:
df=read.delim("/Volumes/test.txt",header=TRUE,sep="\t")
df=df[order(df$ID),]
df$Timepoint<-factor(df$Timepoint,levels=c("w0","w1","w6","w7","w8","w10"))
df$Phase<-factor(df$Phase,levels=c("pre_treat","treat","post_treat"))
ggplot(df,aes(x=Timepoint,y=ID,shape=Data))+
geom_point(aes(color=Data,shape=Data),size=3.5, position = position_jitter(w = 0.1, h = 0))+
facet_wrap(~Phase,scales="free_x")+
scale_shape_manual(values=c(16,0,17))+
scale_colour_manual(values=c("black","black","gray60"))+
theme_bw()+ylab("ID")+
theme(axis.text.x = element_text(angle = 45, hjust = 1))
我遇到的问题是点太近,每个符号的顺序似乎是随机表示的。
我尝试同时使用 position_jitter 和 position_dodge,但我仍然获得对角线方向或重叠点。
非常感谢您的帮助!
您可以使用 position_dodge2() 而不是 position_dodge() 并在 scale_x_discrete 中设置 expand(..) 参数以查看要点:
df = expand.grid(
ID=c("P1","P2"),
Timepoint = c("w0","w1","w6"),
Phase = c("pre_treat","treat","post_treat"),
Data =c("Transcriptomics","Methylation","IM")
)
#sample some data
df=df[runif(45)>0.1,]
ggplot(df,aes(x=Timepoint,y=ID,shape=Data))+
geom_point(aes(color=Data,shape=Data),size=3.5,
position = position_dodge2(w = 0.75))+
facet_wrap(~Phase,scales="free_x")+
scale_shape_manual(values=c(16,0,17))+
scale_colour_manual(values=c("black","black","gray60"))+
scale_x_discrete(expand=c(0.1, 0.5))+
theme_bw()+ylab("ID")+
theme(axis.text.x = element_text(angle = 45, hjust = 1))
我有一个类似于下面的数据table:
df=read.delim("/Volumes/test.txt",header=TRUE,sep="\t")
df=df[order(df$ID),]
df$Timepoint<-factor(df$Timepoint,levels=c("w0","w1","w6","w7","w8","w10"))
df$Phase<-factor(df$Phase,levels=c("pre_treat","treat","post_treat"))
ggplot(df,aes(x=Timepoint,y=ID,shape=Data))+
geom_point(aes(color=Data,shape=Data),size=3.5, position = position_jitter(w = 0.1, h = 0))+
facet_wrap(~Phase,scales="free_x")+
scale_shape_manual(values=c(16,0,17))+
scale_colour_manual(values=c("black","black","gray60"))+
theme_bw()+ylab("ID")+
theme(axis.text.x = element_text(angle = 45, hjust = 1))
我遇到的问题是点太近,每个符号的顺序似乎是随机表示的。
我尝试同时使用 position_jitter 和 position_dodge,但我仍然获得对角线方向或重叠点。 非常感谢您的帮助!
您可以使用 position_dodge2() 而不是 position_dodge() 并在 scale_x_discrete 中设置 expand(..) 参数以查看要点:
df = expand.grid(
ID=c("P1","P2"),
Timepoint = c("w0","w1","w6"),
Phase = c("pre_treat","treat","post_treat"),
Data =c("Transcriptomics","Methylation","IM")
)
#sample some data
df=df[runif(45)>0.1,]
ggplot(df,aes(x=Timepoint,y=ID,shape=Data))+
geom_point(aes(color=Data,shape=Data),size=3.5,
position = position_dodge2(w = 0.75))+
facet_wrap(~Phase,scales="free_x")+
scale_shape_manual(values=c(16,0,17))+
scale_colour_manual(values=c("black","black","gray60"))+
scale_x_discrete(expand=c(0.1, 0.5))+
theme_bw()+ylab("ID")+
theme(axis.text.x = element_text(angle = 45, hjust = 1))