【发布时间】:2015-09-27 19:09:25
【问题描述】:
假设 is.character(MyColours) = TRUE 其中 MyColours 包含许多十六进制颜色值。
如何确保当我想使用 ggplot 绘图时,我可以确保 MyColours[1] 将始终用于表示“Ford”,而 MyColour[3] 在我无法保证订单时将表示“Toyota” “福特”或“丰田”将出现在我用来绘制的观察结果中。
虽然下面的 geo_bar 示例很有帮助,并且确实提醒我将列名添加到 MyColours,但我希望绘制线条而不是条形
ggplot(MyData, aes(x = TimePeriod, y = CountOfItems,
group = Account, color = scale_fill_manual(values = MyColours)))
+ geom_line(size = 1)
+ theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1))
即使length(MyColours) 等于length(unique(MyData$Account)),我也会收到错误Aesthetics must either be length one, or the same length as the dataProblems:scale_fill_manual(values = MyColours)
样本数据
dput(MyData)
structure(list(Account = structure(c(1L, 2L, 1L, 2L), .Label = c("Mazda RX4",
"Toyota Corolla"), class = "factor"), CountOfItems = c(14, 120,
23, 345), TimePeriod = structure(c(1L, 2L, 2L, 3L), .Label = c("2010-12",
"2011-01", "2011-02"), class = "factor")), .Names = c("Account",
"CountOfItems", "TimePeriod"), row.names = c(NA, -4L), class = "data.frame")
是否可以将 scale_fill_manual 与线图一起使用?
【问题讨论】:
-
请在提出 R 问题时提供可重现的示例:stackoverflow.com/questions/5963269/…