为了改变线的类型就应该把linetype=dat.Function
的aes()
内,然后使用scale_linetype_manual()
改变线的类型,类似与线大小 - 放size=dat.Function
内部aes()
,然后使用scale_size_manual()
改变线宽度(应删除size=0.5
表格stat_density()
)要标记垂直线的位置,一种可能性是用scale_x_continuous()
更改x轴上的中断,或者在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()
和theme()
玩。首先,在scale_x_continuos()
中设置了breaks=
和labels=
,并且对于位置800使用x=800
。现在x轴下有6个数字。使用theme()
和axis.text.x=
您可以更改文本的功能。如果给值的矢量用于改变则每个轴文本将具有单独的功能的元件(I设置为2元件不同的特征(文本X = 800))
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")))
1为图纸。 – Eduardo 2014-11-07 09:39:16