问题描述
我正在寻找一种方法来隐藏下面代码创建的情节中的一个传奇故事。要按日期缩放点颜色,我不得不将日期转换为数字,而且我宁愿不在日历上显示日期图例。另一方面,形状图例是显示的重要信息。我知道 legend.position =none会完全删除这个图例,但这就给我带来了如何沟通形状背后的意义的问题。
I am looking for a way to hide one of the aestetic legends from the plot created with the code below. To scale the point color by date, I had to convert the dates into numbers, and I'd rather not show the date legend on the plot. On the other hand, the shape legend is important information to display. I understand that legend.position="none" will completely remove the legend, but then that leaves me with the problem of how to communicate the meaning behind the shapes.
library(ggplot2) w<-read.table("data.txt", header=TRUE) pt.data <- w[w$dt==min(w$dt),] p <- ggplot(data=w, aes(OAD,RtgValInt,color=dt,shape=Port)) + geom_jitter(size=3, alpha=0.75) + scale_colour_gradient(limits=c(min(w$dt), max(w$dt)), low="#9999FF", high="#000066") + geom_point(data=pt.data, color="red", size=3, aes(shape=Port)) print(p)
data.txt 文件包含下面的行。
Date Port OAD RtgValInt dt 12/31/2010 Grp1 1.463771 1.833333 14974 12/31/2010 Grp2 1.193307 2.071429 14974 11/30/2010 Grp1 1.454115 1.833333 14943 11/30/2010 Grp2 1.127755 2.071429 14943 10/29/2010 Grp1 1.434965 2.000000 14911 10/29/2010 Grp2 1.055758 2.071429 14911 09/30/2010 Grp1 1.441773 2.000000 14882 09/30/2010 Grp2 1.077799 2.071429 14882
推荐答案
层级。如果将色彩审美从最初的调用移动到ggplot到抖动层,那么似乎会产生您所追求的效果。我有点困惑,至于为什么你会想根据日期着色,而没有提供关于颜色的含义的关键......但这是一个更哲学的问题让你思考。
You can suppress the legends at the layer level. If you move the colour aesthetic from the initial call to ggplot to the jitter layer, that seems to give the effect you are after. I'm a bit confused though as to why you would want to colour based on date and not provide the key as to what the colors mean...but that's a more philosophical question for you to ponder.
ggplot(data=w, aes(OAD,RtgValInt,shape=Port)) + geom_jitter(size=3, alpha=0.75, color=dt, legend = FALSE) + scale_colour_gradient(limits=c(min(w$dt), max(w$dt)),low="#9999FF", high="#000066") + geom_point(data=pt.data, color="red", size=3, aes(shape=Port))
这篇关于如何从ggplot2图例中删除审美的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!