问题描述
不幸的是,我认为这是一个很难复制的项目,但是我认为这个问题应该足够简单,以可视化的方式回答...
Unfortunately, I think this is a tough item to reproduce, but I think the question should be simple enough to answer with a visual...
我想在geom_point中为三个特定尺寸构建图例.
I'd like to build a legend for three specific dimensions in geom_point.
有曲棍球迷吗?
我想为在此图表上具有颜色的尺寸创建图例.他们是我想强调的三个不同的角色,剧情中的其余要点是一般的杂音,但对于视觉来说是必需的.
I'd like to build a legend for the dimensions that have colors on this chart. They are three different players I'd like to highlight, the rest of the points on the plot being general noise, but necessary for a visual.
我认为,这里的传奇故事比唱片更吸引人.
In my opinion, here a legend would be more appealing than labels.
我知道这有点荒谬而无法重现,但是我希望这个问题足够笼统(尽管我找不到能满足我所寻找目的的答案),以便可以轻松解决.
I know this is kind of ridiculous without being able to reproduce, but I hope the question is general enough (though I couldn't find an answer that satisfied what I was looking for) that it can be easily solved.
很高兴提出问题.
谢谢!
推荐答案
已解决...代码如下:
Solved... the code looks like this:
library(ggplot2)
Offense <- read.csv("Offense1.csv")
plot <- ggplot(Offense[Offense$Gm>20,], aes(CF.Rel, SCF.Rel)) + geom_point() +
geom_point(data=Offense[Offense$Name == "Eric.Staal",], aes(colour="Eric Staal"), size=4) +
geom_point(data=Offense[Offense$Name == "Rick.Nash",], aes(colour="Rick Nash"), size=4) +
geom_point(data=Offense[Offense$Name == "Tanner.Glass",], aes(colour="Tanner Glass"), size=4)
plot <- plot + labs(title = "Driving Offense",
x = "Relative Corsi For %",
y= "Relative Scoring Chances For %")
plot <- plot + scale_colour_discrete(name="Player")
plot
这里的关键是使美学色彩成为您想在图例中包含的尺寸.
They key here was to make the aesthetic color the dimension you want to include in the legend.
这篇关于R-ggplot中特定点的图例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!