图例和标记平滑拟合线 + 使用 ggplot2 的附加线

End*_*Bee 5 r ggplot2

我正在对网络数据中的一些模式进行可视化,并且在标记线时遇到了一些问题,其中我有多种类型的线:

  1. 每个因素的黄土线(网络)
  2. y=4000 处的基线
  3. 作用于所有数据的游戏线(未考虑因素)

现在,堆栈溢出帮助我做到了这一点(谢谢!),但我觉得我遇到了我需要做的事情:

A. 为第 3 行提供图例条目

B. 标记图表上的每一行(按照 #1 #2 #3 - 所以总共 8 行)

这是我到目前为止的代码:

p <- ggplot(network_data, aes(x=timeofday,y=dspeed, colour=factor(network)))+stat_smooth(method="loess",formula=y~x,se=FALSE)
p <- p + stat_function(fun=function(x)4000, geom="line", linetype="dashed", aes(colour="Baseline"))
p <- p + xlab("Time of Day (hr)") + ylab("Download Speed (ms)")
p <- p + theme(axis.line=element_line(colour="black"))

# add the gam line, colouring it purple for now
q <- layer(data=network_data, mapping=aes(x=timeofday,y=dspeed), stat="smooth"
       , stat_params=list(method="gam", formula=y~s(x), se=FALSE), geom="smooth", geom_params=list(colour="purple"), position=position_identity()) 

graph <- p+q # add the layer

#legend
graph <- graph+scale_colour_discrete(name="network")

# set up the origin correctly and axes etc
graph2 <- graph + scale_y_continuous(limits=c(0,6500), expand=c(0,0), breaks=c(0,1000,2000,3000,4000,5000,6000)) + scale_x_datetime(limits=as.POSIXct(c("2015-04-13 00:00:01","2015-04-13 23:59:59")), expand = c(0, 0), breaks=date_breaks("1 hour"), labels=date_format("%H"))
Run Code Online (Sandbox Code Playgroud)

很高兴考虑其他软件包,但 ggplot2 似乎是迄今为止最好的。

无论如何,当我试图自动生成这些图形时,是否可以“自动”(通过编程)执行此操作?

我已在此处将数据作为 .Rda 文件提供:

https://dl.dropboxusercontent.com/u/5268020/network_data.Rda

这是当前情节的图像:

在此处输入图片说明

Uma*_*mao 0

对于 q B,尝试annotate手动编码每行标签的位置和文本。考虑到传说似乎没有必要。 http://docs.ggplot2.org/current/annotate.html