【发布时间】:2015-04-21 13:12:25
【问题描述】:
我的数据框(请参阅下面的链接)包含多个模型的输出,我想根据以下内容对其进行“分类”:
- 型号名称(9 个型号)-> 9 种形状填充颜色
- 模型域(每个模型都有以下两个之一:“MED”或“EURO”)-> 两种空心形状类型
- 原始分辨率(每个模型都有两个“版本”:“HR”和“LR”)-> 2 种形状轮廓颜色
此外,还包括一个单独的观测数据集,应以自己的颜色和填充形状显示。
所以总的来说,我有 9x2=18 个点类型,每个点类型还有一个“域”标签,外加一个观察点类型。
以下是最简单的开始,但根本不起作用。另外,我不想使用 scale_*_manual 为每个项目手动指定颜色和形状。
library(ggplot2)
#Sorry for the wget, I can't seem to make load() read the url directly
system("wget https://copy.com/LrEznd8QCmzVBNyz/df_pr_PDF_alps_044.Rdata?download=1")
load("df_pr_PDF_alps_044.Rdata?download=1") #This loads df
colnames(df) #Take a look at the columns
ggplot(data=df[which(df$PDF > 0),], aes(x=x, y=PDF)) +
geom_point(aes(shape=domain, colour=nativeresolution, fill=model), alpha=0.7, size=2)+
scale_shape_manual(values=c(21,22,23))
我已经尝试了一些修复,例如此处建议的修复:
ggplot2: One legend with two visual properties derived from common variable
Combine legends for color and shape into a single legend
How to merge colour and shape?
但我似乎找不到解决这个看似简单的问题的方法。
【问题讨论】:
-
关于“填充”和“轮廓”的形状以及“我不想使用
scale_*_manual为每个项目手动指定颜色和形状”,请阅读?pch:“21:25可以着色和填充不同的颜色”。因此,我认为您需要将变量的级别映射到您定义的pch:smanually。 -
@Henrik 是的,你完全正确,21 到 25 是唯一受填充影响的,所以我应该使用这些。我忘了。我将编辑示例以使用这些形状。仍然效果不佳:所有的传说都搞砸了。