我正在尝试将条形图的颜色分别调整为“#054C70”和“#05C3DE”。当我使用以下代码时:
p2 <- ggplot(b, aes(x = Currency, y = amount, color = inbound_outbound)) + geom_bar(position = "dodge", stat = "identity") + labs(title = "Subset Avg. Order Amount") + theme(axis.text.x = element_text(angle = 90, hjust = 1))
+ scale_fill_manual(values = c("#054C70","#05C3DE"))
我收到以下错误: + scale_fill_manual(值= c(“#054C70”,“#05C3DE”))中的错误: 一元运算符的参数无效
我正在R中进行编码。任何帮助将不胜感激。谢谢。
答案 0 :(得分:1)
这里发生了一些事情。
+
符号应位于第一行代码的结尾。fill
映射(而不是color
映射。< / li>
使用菱形dataset
中的示例,因为我没有您正在使用的特定数据集,
library(dplyr)
library(ggplot2)
## filter dataset to only have two different colors to best match the example
df <- diamonds %>% filter(color %in% c("D","E"))
## change color to fill in this first line
p2 <- ggplot(df, aes(x = cut, y = price, fill=color)) +
geom_bar(position = "dodge", stat = "identity") +
labs(title = "Subset Avg. Order Amount") +
## make sure the plus sign is at the end of this line
theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
scale_fill_manual(values = c("#054C70","#05C3DE"))
这将产生以下情节:example plot