要更改线的类型,您应该放在linetype=dat.Function里面aes()然后使用scale_linetype_manual()来更改线类型,类似于线条大小 - 放在size=dat.Function里面aes()然后使用scale_size_manual()来更改线宽(您应该删除size=0.5表格stat_density())要标记垂直线的位置,一种可能性是更改在 x 轴上用 . 中断scale_x_continuous()或在绘图内添加一些文本annotate()。
ggplot(dat.sub,aes(dat.Freq,color=dat.Function,
linetype=dat.Function,size=dat.Function))+
stat_density(geom="path",position="identity")+
scale_color_manual(values=pal)+
geom_vline(xintercept=800,colour="red",linetype="longdash")+
scale_linetype_manual(values=c(2,1,1))+
scale_size_manual(values=c(2,0.8,0.8))+
scale_x_continuous(breaks=c(0,800,2500,5000,7500,10000))+
annotate("text",label="x=800",x=800,y=-Inf,hjust=0,vjust=1)

如果要将文本放置x=800在轴下方,一种方法是使用网格对象,另一种可能是使用scale_x_continuous()and theme()。首先,在scale_x_continuos()设置800 位置使用breaks=和。现在 x 轴下有 6 个数字。使用并且您可以更改文本的功能。如果您为要更改的元素提供值向量,则每个轴文本将具有单独的特征(我为 2. 元素设置了不同的特征(文本 x=800))labels=x=800theme()axis.text.x=
ggplot(dat.sub,aes(dat.Freq,color=dat.Function,
linetype=dat.Function,size=dat.Function))+
stat_density(geom="path",position="identity")+
scale_color_manual(values=pal)+
geom_vline(xintercept=800,colour="red",linetype="longdash")+
scale_linetype_manual(values=c(2,1,1))+
scale_size_manual(values=c(2,0.8,0.8))+
scale_x_continuous(breaks=c(0,800,2500,5000,7500,10000),
labels=c(0,"x=800",2500,5000,7500,10000))+
theme(axis.text.x=
element_text(color=c("grey35","red","grey35","grey35","grey35"),
size=rel(c(1,1.2,1,1,1,1)),
face=c("plain","bold","plain","plain","plain","plain")))
