我正在对网络数据中的一些模式进行可视化,并且在标记线时遇到了一些问题,其中我有多种类型的线:
现在,堆栈溢出帮助我做到了这一点(谢谢!),但我觉得我遇到了我需要做的事情:
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 …Run Code Online (Sandbox Code Playgroud)